c# - Application stops when SQL Server CE command executed -


when debug program works fine until gets to:

sqlcecommand mycommand = new sqlcecommand("insert dbo.login values ('" + usernamebox.text + "','admin', '" + saltedcryps + "', '" + hashedresult + "')", myconnection);                     mycommand.executenonquery();                     messagebox.show("thanks registering!");                     this.close(); 

then stops, closes form , other forms except mdi form. can help?

here code:

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.security.cryptography; using system.data.sqlserverce;  namespace event_control {  public partial class registerscreen : form {     public registerscreen()     {         initializecomponent();     }      public static string a;      private void registerscreen_load(object sender, eventargs e)     {     }      private void cancelbutton_click(object sender, eventargs e)     {         this.close();     }      public string radiobuttons()     {         if (userbutton.checked)         {             return "user";         }         else if (adminbutton.checked)         {             return "admin";         }         else         {             messagebox.show("you must select account type");             return "error";         }     }      private bool checkifusernameexists()     {         sqlceconnection myconnection = new sqlceconnection("data source=eventcontrol.sdf");          try         {             myconnection.open();         }         catch (exception ex)         {             messagebox.show(ex.tostring());         }         string checkuser = "select * login name = '" + usernamebox.text + "' ";          sqlcecommand checkuser = new sqlcecommand(checkuser, myconnection);          if (checkuser.executescalar() != null)         {             messagebox.show("username exists");             return false;         }         else         {             return true;         }     }      private bool checkpasswordsmatch()     {         if (!passwordbox.text.equals(confirmpasswordbox.text))         {             messagebox.show("sorry, passwords not match, try again", "password error");             passwordbox.text = "";             confirmpasswordbox.text = "";             return false;         }         else             return true;     }      private bool checkusernameempty()     {         if (usernamebox.text == "")         {             messagebox.show("enter username");             return false;         }         else             return true;     }      private bool checkpasswordsnotempty()     {         if (passwordbox.text == "")         {             messagebox.show("password box empty");             return false;         }         else             return true;     }      private string saltpassword(int size)     {         rngcryptoserviceprovider crypto = new rngcryptoserviceprovider();         byte[] buff = new byte[size];         crypto.getbytes(buff);         return convert.tobase64string(buff);     }      private string hashpassandsalt(string passwithsalt)     {         hashalgorithm hashalg = new sha256cryptoserviceprovider();         byte[] bytvalue = system.text.encoding.utf8.getbytes(passwithsalt);         byte[] bythash = hashalg.computehash(bytvalue);         string base64 = convert.tobase64string(bythash);         return base64;     }      private void registerbutton_click(object sender, eventargs e)     {         = radiobuttons();         string saltedcryps = saltpassword(10);         string passwithsalt = (passwordbox.text + saltedcryps);         string hashedresult = hashpassandsalt(passwithsalt);          if (a == "admin")             if (checkusernameempty() && checkifusernameexists() && checkpasswordsnotempty() && checkpasswordsmatch())             {                  {                      sqlceconnection myconnection = new sqlceconnection("data source=eventcontrol.sdf");                     try                     {                         myconnection.open();                     }                     catch (exception ex)                     {                         messagebox.show(ex.tostring());                     }                     sqlcecommand mycommand = new sqlcecommand("insert dbo.login values ('" + usernamebox.text + "','admin', '" + saltedcryps + "', '" + hashedresult + "')", myconnection);                     mycommand.executenonquery();                     messagebox.show("thanks registering!");                     this.close();                 }             }             else             {             }         else if (a == "user")         {             if (checkusernameempty() && checkifusernameexists() && checkpasswordsnotempty() && checkpasswordsmatch())             {                 {                     sqlceconnection myconnection = new sqlceconnection("data source=eventcontrol.sdf");                     try                     {                         myconnection.open();                     }                     catch (exception ex)                     {                         messagebox.show(ex.tostring());                     }                     sqlcecommand mycommand = new sqlcecommand("insert dbo.login values ('" + usernamebox.text + "','user', '" + saltedcryps + "', '" + hashedresult + "')", myconnection);                     mycommand.executenonquery();                     messagebox.show("thanks registering!");                     this.close();                 }             }             else             {             }         }      } } 

like said, gets run command part in if (a == "admin") part, stops working. when user.

info: have copied program old program, old program used sql server, 1 use sql server ce, can embed program , use on computer. not show message box, not add information database or anything, brings blank mdi screen, when supposed go login screen after adding relevant information

thanks guys


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -