在开发中用MSSQL 的多,而Access数据库的少,下面简单说下Access数据库的连接设置:
web.config配置
<configuration>
<appSettings/>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|/skdb.mdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
</connectionStrings>
用于测试连接状态的代码:
public string OpenDB()
{
string msg;
OleDbConnection MyOleDB = new OleDbConnection();
MyOleDB.ConnectionString = WebConfigurationManager.ConnectionStrings["MyJetConn"].ConnectionString;
try
{
MyOleDB.Open();
msg = "server vision:" + MyOleDB.ServerVersion + "connection is " + MyOleDB.State.ToString();
return (msg);
}
catch (Exception err)
{
msg = err.Message;
return (msg);
}
finally {
MyOleDB.Close();
}
}