By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

System Error when trying to call Stored Procedure from code

P: n/a
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();
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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." <an*******@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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();

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.