Access数据库在Web.Config文件中的配置

在开发中用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();
        }
    }

 

上一篇:Sass wikipedia


下一篇:HTTP运行时的简单应用