c# - ExecuteNonQuery() not responding/working -
i have problem application, had worked before. application connects oracle database. @ moment want add new account. in c# code have database class following method:
public void addaccount(string name, string addres, string username, string password) { string query = "insert account(id, name, addres, username, password, datecreated, game_id) values(account_seq.nextval,:name,:addres,:username,:password, sysdate, 1)"; openconnection(); try { oraclecommand command = new oraclecommand(query, connection); oracleparameter[] parameters = new oracleparameter[] { new oracleparameter(":name", name), new oracleparameter(":addres", addres), new oracleparameter(":username", username), new oracleparameter(":password", password) }; command.parameters.addrange(parameters); command.executenonquery(); system.windows.forms.messagebox.show("welcome " + username + "! can login new account."); } catch (oracleexception ex) { system.windows.forms.messagebox.show(ex.message); } closeconnection(); }
here openconnection
method connects me database:
public bool openconnection() { try { connection = new oracleconnection(); string user = "***"; string pw = "***"; connection.connectionstring = "user id=" + user + ";password=" + pw + ";data source=" + " //localhost:1521/xe" + ";"; //orcl de servicename (kan anders zijn, afhankelijk van de oracle server die geinstalleerd is. mogelijk ook oracle express: xe //system.windows.forms.messagebox.show("connectie met database"); connection.open(); //system.windows.forms.messagebox.show("test"); return true; } catch (oracleexception) { return false; } }
and last here method main form want add new member:
private void btnregister_click(object sender, eventargs e) { database = new database(); database.addaccount(tbregistername.text, tbregisteraddress.text, tbregisterusername.text, tbregisterpassword.text); database.addachievement1(); }
my connection database works , tested messagebox. form works. strange thing won't past command.executenonquery();
not give error or anything. hangs/crashes.
all data within parameters right , said, has worked before. find strange not work now. haven't changed crucial.
from experience executenonquery()
method can fail if have no inet connection or database not connected application. none of these true. wondering if of experts know problem be.
if openconnection()
fails no feedback in addaccount()
.
try:
public void addaccount(string name, string addres, string username, string password) { .... if (openconnection()) { ///continue } else { ///log error } }
this approach can specify problem lies.
Comments
Post a Comment