asp.net中读取Access连接字符串问题
我看到有两种方式: 第一种 在web.config中添加: <connectionStrings> <add name="JiDiweb" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|JiDiweb.mdb" /> </connectionStrings> 然后在DBHelper.cs类中读取 string connectionString = ConfigurationManager.ConnectionStrings["JiDiweb"].ConnectionString; 第二种 在web.config中添加: <appSettings> <add key="AccessConn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="/> </appSettings> 然后在DBHelper.cs类中读取 string connectionString =ConfigurationManager.AppSettings["AccessConn"] + Server.MapPath("/App_Data/JiDiweb.db"); 我看了这两种方法第二种呢,必须把dbhelper.cs类放在App_code文件夹中。否则会提示server.mappath没有应用命名空间。 现在我的项目是采用三层架构。我在DAL层中建了DBHelper类。并用了第一种连接方法,所以我想问下两种方法有什么区别吗?更IIS得虚拟目录搭上关系吗?忘高手提示下。谢谢!
建类库不会默认添加System.Configuration的引用引用 建类库不会默认添加System.Web的引用 可以在添加引用后使用 System.Web.HttpContext.Current.Server.MapPath()找到
相关问答:
select top 12 * from Product where [id] not in (select top 12 [id] from Product) 这样可以分页,但是我在后面想加个条件 select top 12 * from Product where [id] not in (select top 12 [id] from Prod ......
C# code: SqlConnection conn = CsDB.sqlcon(); SqlDataAdapter da = new SqlDataAdapter("select fwCoding from bjmuma_fwCoding where OrderNumber='" + Order + & ......
3个radioButton 一个Button 一个label C# code: protected void Button1_Click(object sender, EventArgs e) { string str = null; RadioButton rdo=(RadioButton)sender; ......
就是一个按钮,点击之后打开对话框,然后选取图片。就这样上传。。 怎么实现。在网上搜到那么多的代码,全是很多的那种,不知道,看不下去。 所以在这里想请大哥大姐帮帮忙。 使用自带的fileupload控件可以实现 ......