c# - Code is WRONG but no error is raised -


i have written code in form "load" event

        messagebox.show("message 1");         string strconnectionstring = @"data source=hb-vaio\sqlexpress;initial catalog=db1;integrated security=true;pooling=false";         sqlcommand cmdaddpackage = new sqlcommand("addpackage");         sqlconnection con = new sqlconnection();         con.connectionstring = strconnectionstring;          cmdaddpackage.commandtype = commandtype.storedprocedure;         cmdaddpackage.parameters.add(new sqlparameter("@guidoutput",sqldbtype.uniqueidentifier)).direction = parameterdirection.output;          guid gui = (guid) cmdaddpackage.executescalar();   // error should raised there no error         messagebox.show(gui.tostring());         cmdaddpackage.connection.close();         textbox1.text = gui.tostring();         messagebox.show("end"); 

i know code wrong! , should raise "cannot open database "db1" requested login. login failed. login failed user 'hb-vaio\sony'." in line 8, when run program no error raised, first message box pops out there no sign of second , third message box , form loads successfully.

the wrong things code these :

  • my database name "db" in code used "db1".

  • connection cmdaddpackage not set.

when add same code button1_click event, shows error.

can me why happens ?

i didn't find answer :(

what ui frameworks use? .net ui frameworks indeed provide "load" events, happen silence exceptions happen during even-handlers, "to provide better ui experience end user".

you can check if exceptions thrown in output panel under debugger. if see "first chance exception" - here have it, ui framework "quiet one".

add try-catch, or add application.unhandledexception eventhandler, , try bear quiet ui..

if recall correctly, wpf liked silently skip exceptions, while winforms tended crash instantly. may wrong here.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -