本文实例讲述了asp.net通过配置文件连接Access的方法。分享给大家供大家参考。具体分析如下:
这里数据库blog.mdb存放在App_Data中
配置文件
1
2
3
4
5
6
7
|
< connectionStrings > //方法一 < add name = "access_conn" connectionString = "Provider=Microsoft.Jet.Oledb.4.0;data source=" /> < add name = "access_path" connectionString = "~/App_Data/blog.mdb" /> //方法二 < add name = "blogConn" connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\blog.mdb;Persist Security Info=True" /> </ connectionStrings > |
cs 中 调用:
1
2
3
4
5
6
7
8
|
string sConn = "" ; //调用一 sConn = ConfigurationManager.ConnectionStrings[ "access_conn" ].ConnectionString + HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings[ "access_path" ].ConnectionString); //调用二 sConn = ConfigurationManager.ConnectionStrings[ "blogConn" ].ConnectionString; OleDbConnection conn = new OleDbConnection(sConn); conn.Open(); |
希望本文所述对大家的asp.net程序设计有所帮助。