当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Debugger not finishing the method on step through

问题描述:

I have a fairly simple piece of C# code that I use often

 SqlCommand sql = new SqlCommand();

sql.Connection = new SqlConnection(getConnectionString());

sql.CommandText = @"update [Reporting].[dbo].[Customer_Master]

set groupID = @groupID

where customer = @customerID";

sql.Parameters.Add(new SqlParameter("@groupID", groupID));

sql.Parameters.Add(new SqlParameter("@customer", customer));

sql.Connection.Open();

sql.ExecuteNonQuery();

sql.Connection.Close();

sql.Dispose();

For some reason it wasn't updating my DB correctly so I decided to add a break point at the beginning of the method and step through each line to make sure my variables were coming in correctly.

However, the method closes after sql.Connection.Open(), as in it just returns me back to the main code.

Any thoughts?

Thanks.

Edit: I found the problem. I had used the wrong param name. I still find it odd that it closed out the method after opening the connection without throwing an error though.

网友答案:

You are either throwing some sort of exception here or it may be a timeout error when you are stepping through .Open. But I agree with dash, start out by putting it in a try/catch, this should always be your first step.

分享给朋友:
您可能感兴趣的文章:
随机阅读: