网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 asp.net连接access数据库路径问题
范文
    解决方案一:
    在 Web.Config 中配置 Access 数据库教程驱动和数据库文件名称。
    请看代码
    <appSettings>
    <add key="DBDriver" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source ="/>
    <add key="DBName" value="Company.mdb"/>
    </appSettings>
    在数据库访问层,如 OleDBHelper.cs 中获得 Access 数据库链接字符串。
    /**//// <summary>
    /// 从Web.Config取得数据库联接字符串
    /// </summary>
    //从配置文件中得到数据库名称
    public static readonly string DBName = ConfigurationManager.AppSettings.Get("DBName").ToString();
    //从配置文件中得到数据库驱动
    public static readonly string DBDriver = ConfigurationManager.AppSettings.Get("DBDriver").ToString();
    //得到数据库连接字符串
    private static string DBConnectionString = DBDriver + HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/App_Data/") + DBName;
    //建立数据库连接对象
    private static OleDbConnection OleDbConn = new OleDbConnection(DBConnectionString);
    这样设置后,无论在任何子目录,都能通过以上代码正确的访问数据库。
    解决方案二:
    <appSettings>
    <add key="SQLConnString" value="provider=microsoft.jet.oledb.4.0;data source="/>
    <add key="dbPath" value="~/App_Data/mydata.mdb"/>
    </appSettings>
    程序中的数据访问类中我把"SQLConnString"和"dbPath"取出来连接成一个字符串"CONN_STRING_NON_DTC"
    public static readonly string CONN_STRING_NON_DTC = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbPath"]) + ";";
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/18 12:25:48