c# - Connect to a database not created yet? -
how create sql compact edition database? have tried figure out, searched internet , cant find (but again, how search this?!). here code far:
checkpasswordsmatch(); sqlceconnection myconn = new sqlceconnection(); sqlcecommand mycommand = new sqlcecommand( @"create database ""pwdb.sdf"" databasepassword '" + textbox1.text + "'"); mycommand.executenonquery(); what put on connection part? dont understand.
update: decided create database incorporate application, , check if there value (admin password) dedicated record master.
here new code:
application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); sqlceconnection myconn = new sqlceconnection("data source = pwdb.sdf;"); sqlcecommand checkpass = new sqlcecommand("select * pw name = master;",myconn); try { myconn.open(); } catch (exception ex) { messagebox.show(ex.tostring()); } if (checkpass.executenonquery() != null) { application.run(new entermasterpassword()); } else application.run(new mainpassset()); the problem is, when execute now, get:
an unhandled exception of type 'system.data.sqlserverce.sqlceexception' occurred in system.data.sqlserverce.dll
any ideas anyone??
try using sqlceengine class. class can create new database:
using (sqlceengine engine = new sqlceengine()) { engine.localconnectionstring = yourconnectionstring; engine.createdatabase(); }
Comments
Post a Comment