.net连接两种数据库的设置....

    技术2022-05-11  81

    1.Access数据库

    web.config文件:<appSettings>    <add key="DBPath" value="database/test.mdb" />    <add key="Connection" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="/>  </appSettings> test.aspx.cs文件:        string strDBPath = System.Configuration.ConfigurationSettings.AppSettings["DBPath"];        string strConn = System.Configuration.ConfigurationSettings.AppSettings["Connection"] + Server.MapPath(strDBPath);        OleDbConnection myConnection = new OleDbConnection(strConn);

    2.Sql Server数据库

    web.config文件:<appSettings>    <add key="Conntction" value="server=localhost;uid=sa;pwd=system;database=test"/> </appSettings>test.aspx.cs文件:        string strConn = "server=localhost;uid=sa;pwd=system;database=test";        SqlConnection myConnection = new SqlConnection(strConn);


    最新回复(0)