2007 database
Oledbconnection conn = new oledbconnection ("provider = Microsoft. Ace. oledb.12.0; Data Source = database1.accdb ");
2003 database
Con = new oledbconnection ("provider = Microsoft. Jet. oledb.4.0; Data Source = \" database. mdb \ "; Jet oledb: Database Password = aking ");
********************
Private Static void openconnection ()
{
If (conn. State = connectionstate. Closed)
{
Conn. connectionstring = "provider = Microsoft. Jet. oledb.4.0; Data Source ="
+ System. Web. httpcontext. Current. server. mappath (configurationmanager. connectionstrings ["dbpath"]. tostring ());
Comm. Connection = conn;
Try
{
Conn. open ();
}
Catch (exception E)
{
Throw new exception (E. Message );
}
}
}
<Connectionstrings>
<Add name = "dbpath" connectionstring = "~ /App_data/Web. mdb "/>
<! -- Database path, previous ~ Must be retained -->
</Connectionstrings>
How can I write it after changing to access?
<Connectionstrings>
<Add name = "dbpath" connectionstring = "~ /App_data/Web. mdb "/>
<! -- Database path, previous ~ Must be retained -->
</Connectionstrings>
Private Static void openconnection ()
{
If (conn. State = connectionstate. Closed)
{
Conn. connectionstring = "provider = Microsoft. Jet. oledb.4.0; Data Source ="
+ System. Web. httpcontext. Current. server. mappath (configurationmanager. connectionstrings ["dbpath"]. tostring ());
Comm. Connection = conn;
Try
{
Conn. open ();
}
Catch (exception E)
{
Throw new exception (E. Message );
}
}
}
You just need to add one of the two. The previous one is written in Web. config.
************************** * *******************
Public static oledbconnection createdb ()
{< br> return New oledbconnection (configurationmanager. appsettings ["oledbconnectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"]);
}