System Error when trying to call Stored Procedure from code

G

Guest

Hi

I am fairly new to .NET, and I am having a hard time to call a stored procedure from C# code in a windows application
I have tested my connection (and login) several time and it is OK. If I try to do a query it works, but when I try to call a stored procedure i get the message "System Error". My code is shown below
Any idea what could be the problem
A million thanks

Jenn
------------------------

this.connString = ConfigurationSettings.AppSettings["connString"]
this.con = new SqlConnection(this.connString)

this.procedureName = "MyStoredProcName"
this.cmd = new SqlCommand(this.procedureName, this.con)
this.cmd.CommandType = CommandType.StoredProcedure

SqlParameter param
param = this.cmd.Parameters.Add("@MyParameter", SqlDbType.Int)
param.Direction = ParameterDirection.Output;


this.con.Open()
this.cmd.ExecuteNonQuery()
this.con.Close();
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Jenny,

Is you stored procedure declared correctly:

CREATE PROC MyStoredProcName
(
@MyParameter INT OUTPUT
)
AS
-- the code

if it does, can you wrap the ExecuteNonQuery() call in a try/catch block and
see that the Exception.Message says?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Jenny C. said:
Hi,

I am fairly new to .NET, and I am having a hard time to call a stored
procedure from C# code in a windows application.
I have tested my connection (and login) several time and it is OK. If I
try to do a query it works, but when I try to call a stored procedure i get
the message "System Error". My code is shown below.
Any idea what could be the problem?
A million thanks!

Jenny
-------------------------


this.connString = ConfigurationSettings.AppSettings["connString"];
this.con = new SqlConnection(this.connString);

this.procedureName = "MyStoredProcName";
this.cmd = new SqlCommand(this.procedureName, this.con);
this.cmd.CommandType = CommandType.StoredProcedure;

SqlParameter param;
param = this.cmd.Parameters.Add("@MyParameter", SqlDbType.Int);
param.Direction = ParameterDirection.Output;


this.con.Open();
this.cmd.ExecuteNonQuery();
this.con.Close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top