I have a winforms project which depends on a custom library. Everything with the app is working fine except a problem I can not pin down. Basically I have a form which is created from another form which displays it as a dialog:
DataItems.ImportForm frmImportTextDelimited = new DataItems.ImportForm();
frmImportTextDelimited.ShowDialog();
This dialog form populates a dropdown list from the SqlServer using the below function which is from a class library in the solution:
public class AuthorityTypeSearcher
{
public List<IntValuePair> GetAllAuthorityTypes()
{
List<IntValuePair> returnList = new List<IntValuePair>();
using (var conn = new SqlConnection(Globals.ConnString))
{
var cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT FROM tblAuthorityTypes";
conn.Open();
IntValuePair ivp;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ivp = new IntValuePair();
ivp.TheInt = Convert.ToInt32(rdr["ID"]);
ivp.TheValue = rdr["AuthorityType"].ToString() ;
}
}
return returnList;
}
This function never returns a value, so I set a breakpoint on the line:
conn.Open();
When the code executes, the Visual studio correctly breaks to this line. What is making me crazy is that when I step forward to the line:
SqlDataReader rdr = cmd.ExecuteReader();
The debugger will not move forward to the next line, and code execution appears to return to the UI (the form is displayed). What is also strange is that if I interact with the form (i.e. click a button on the form which populates another field), the debugger breaks again, I return to visual studio, which correctly "breaks" to the line related to that operation. It seems like, for whatever reason, when I get to the line that creates the data reader, code execution simply "leaves" the library and returns to the winforms app.
When code execution appears to have returned to the UI, if I return to visual studio it appears that code execution is continuing, at least I can not click "continue" (play). The code execution is not "paused".
What is also strange is that if I close the form (dialog), it breaks back into the debugger on the line from the main form on the line:
frmImportTextDelimited.ShowDialog();
as though I were still debugging.
Hopefully this makes sense? I can't figure out why, when debugging, I cant step past the line where I create the data reader, and why code execution goes back to the UI, but returns to the debugger with the dialog is closed. No error is ever thrown.
Thanks for any advice!
If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.
This problem occurs because ASP.NET debugging isn't enabled on the application.
Breakpoints break before executing the line on which they are placed.
The explanation of this behavior lies in the behavior of 64 bit code when an exception is raised during Form_Load.
The syntax of your query is wrong. You don't have a column list and this raise a syntax error by your database engine.
But an exception raised during a Form_Load in a 64 bit environment cannot be trapped by the debugger.
A more detailed answer could be found here
You could try to fix your query adding the appropriate field names (or a star * for all fields).
Also try to run your code outside the Visual Studio IDE. You should see the Exception somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With