Connecting to database(MS Access) in asp.net c#(hosting website) -
i have hosted website, , need add database password , log-in information. (ms access db), tried lot can't connect (on local machine works). tried change connection string still doesn't work. database in folder app_data. here's type in login.aspx
page:
oledbconnection con = new oledbconnection(); con.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=" + server.mappath("~\\app_data\\websitedatabase.accdb"); con.open();
this not work. need change? i've put web site on somee.com
did check page on somee connecting access database?
quote somee.com help:
connect ms access database usin dsn-less connection
doka provides dsn-less connection access databases, because faster , there no possible names conflict. of problems in choosing right connection string. here example of tested connection string ms access database:
suppose database resides in “database” subfolder , name “testdb.mdb”.
you’ll have useserver.mappath(“database\testdb.mdb”)
in order physical location of database.
so connection string be:
"provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("database\testdb.mdb")
and way utilize it:
oledbconnection conn = null; oledbdatareader reader = null; try { conn = new oledbconnection( "provider=microsoft.jet.oledb.4.0; " + "data source=" + server.mappath("database/testdb.mdb")); conn.open(); oledbcommand cmd = new oledbcommand("select * table1", conn); reader = cmd.executereader(); datagrid.datasource = reader; datagrid.databind(); } // catch (exception e) // { // response.write(e.message); // response.end(); // } { if (reader != null) reader.close(); if (conn != null) conn.close(); }
Comments
Post a Comment