1

In my program I open a new SQL connection like so:

SqlCeConnection con = new SqlCeConnection(conString);
con.Open();

I can't quite work out when it stopped working, but now, whenever I debug, the program ignores everything past the first line. For example, if I put a breakpoint on "con.Open();" then the breakpoint is not processed - the form is shown as if nothing has happened.

However, if I have a button on the form, it will fire any of those events without hassle.

If more details are required, let me know, and thanks for helping!

NerdJam
  • 41
  • 1
  • 6
  • Have you accidentally disabled debugging? – Brian Dec 19 '13 at 20:32
  • Are you getting any errors? I wonder if it could be timing out or just sitting trying to connect with an incorrect connection string. – shadowjfaith Dec 19 '13 at 20:32
  • 1
    is the breakpoint solid, or is it hollow? – Christian Phillips Dec 19 '13 at 20:33
  • Are these line wrapped inside a try/catch clause? – System Down Dec 19 '13 at 20:34
  • @shadowjfaith No errors whatsoever, and should have mentioned that if I put a breakpoint of the first line then it still breaks at that point. Just nowhere after it. And I have tried moving the first line to various different points and always the same effect - breaks at that line but nowehere after it. – NerdJam Dec 19 '13 at 20:35
  • @christiandev Nope, all solid – NerdJam Dec 19 '13 at 20:36
  • @SystemDown No, they are in a method called by the Form Load event. But, as I say, there is other code both before and after these lines within the method. The code before runs fine, but the code after is ignored. – NerdJam Dec 19 '13 at 20:38
  • are other breakpoints being hit? can you post more of the code around these lines? – Christian Phillips Dec 19 '13 at 20:43

1 Answers1

1

You have an exception, but the Load event is eating it.

Try moving your code to the Shown event instead to see the exception.

See Why the form load can't catch exception?

See VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows

Community
  • 1
  • 1
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Sorry if this is a silly question, but what exactly do you mean about "moving [my] code to the Shown event"? – NerdJam Dec 19 '13 at 21:56
  • @NerdJam In stead of the Load event, use the Shown event, and move the code that you have in the Load event to the Shown event method. There is a bug in WinForms where exceptions get swallowed in the Load event. You should rarely use the Load event anyway. – LarsTech Dec 19 '13 at 22:00
  • Aha, yeah, gotcha, just needed it rephrased a bit. Worked great, thank you! (The problem was I had a semi-colon in my DB password) – NerdJam Dec 20 '13 at 16:54