J
Joel Finkel
Folks,
I have a Sql Server SP that takes several values and stores them as a new row in a single table. It works just fine within the Sql Server Query Analyzer and within Visual Studio.NET's Server Explorer. I used Visual Studio.NET to create the SqlCommand, set it to a Stored Procedure, and let it create the Parameters, which an examination of the code shows that it did correctly.
A WebForm is used to gather the data, and a button is used to trigger the execution of the code that sets the values of the Parameters and execute the SqlCommand. No exception is thrown, but the SqlCommand returns -1, and no row is stored in the database. Using the debugger, I have confirmed that the Parameters are, in fact, being set correctly before the SqlCommand is executed.
I am working in a client/server environment, and debugging is a bit weird. I have to attach to the worker process on the server in order to debug the code. I have not been able to set up Sql Server to allow debugging (although I have tried).
I wonder if there are any suggestions as to what may be going wrong, or what I can do to further debug the problem. Here is the pertinent code:
Thank you in advance.
Joel Finkel
(e-mail address removed)
int num;
SqlTransaction myTrans;
sqlCommand_insert.Parameters["@ID"].Value = memberID; // will be coerced to int4
sqlCommand_insert.Parameters["@RECEIVED_DATE"].Value = NewPaymentDate.SelectedDate.ToString();
sqlCommand_insert.Parameters["@RECEIVED_AMOUNT"].Value = NewPaymentAmt.Text;
sqlCommand_insert.Parameters["@info"].Value = NewPaymentInfo.Value;
if (sqlConnection1.State.ToString() != "Open")
{
sqlConnection1.Open();
}
try
{
myTrans = sqlConnection1.BeginTransaction();
sqlCommand_insert.Connection = sqlConnection1;
sqlCommand_insert.Transaction = myTrans;
num = sqlCommand_insert.ExecuteNonQuery();
if (num == 1)
{
myTrans.Commit();
}
else
{
myTrans.Rollback();
}
Server.Transfer("WebForm1.aspx");
}
catch (SqlException ex)
{
Label1.Text = ex.ToString();
}
I have a Sql Server SP that takes several values and stores them as a new row in a single table. It works just fine within the Sql Server Query Analyzer and within Visual Studio.NET's Server Explorer. I used Visual Studio.NET to create the SqlCommand, set it to a Stored Procedure, and let it create the Parameters, which an examination of the code shows that it did correctly.
A WebForm is used to gather the data, and a button is used to trigger the execution of the code that sets the values of the Parameters and execute the SqlCommand. No exception is thrown, but the SqlCommand returns -1, and no row is stored in the database. Using the debugger, I have confirmed that the Parameters are, in fact, being set correctly before the SqlCommand is executed.
I am working in a client/server environment, and debugging is a bit weird. I have to attach to the worker process on the server in order to debug the code. I have not been able to set up Sql Server to allow debugging (although I have tried).
I wonder if there are any suggestions as to what may be going wrong, or what I can do to further debug the problem. Here is the pertinent code:
Thank you in advance.
Joel Finkel
(e-mail address removed)
int num;
SqlTransaction myTrans;
sqlCommand_insert.Parameters["@ID"].Value = memberID; // will be coerced to int4
sqlCommand_insert.Parameters["@RECEIVED_DATE"].Value = NewPaymentDate.SelectedDate.ToString();
sqlCommand_insert.Parameters["@RECEIVED_AMOUNT"].Value = NewPaymentAmt.Text;
sqlCommand_insert.Parameters["@info"].Value = NewPaymentInfo.Value;
if (sqlConnection1.State.ToString() != "Open")
{
sqlConnection1.Open();
}
try
{
myTrans = sqlConnection1.BeginTransaction();
sqlCommand_insert.Connection = sqlConnection1;
sqlCommand_insert.Transaction = myTrans;
num = sqlCommand_insert.ExecuteNonQuery();
if (num == 1)
{
myTrans.Commit();
}
else
{
myTrans.Rollback();
}
Server.Transfer("WebForm1.aspx");
}
catch (SqlException ex)
{
Label1.Text = ex.ToString();
}