最近在项目中使用到VTemplate,它提供的dataReaderTag标签 提供直接访问数据库的能力,其内部解析提供了对数据库连接操作的封装。但是在访问access的时候 不能使用相对路径,于是找到他的数据库操作文件,找到类DataReaderTag里的 GetDataSource()方法。

在代码块      using (DbConnection dbConnection = dbFactory.CreateConnection())中添加

                string str, str2, str3;
                str = str2 = str3 = setting.ConnectionString;
                if (setting.ProviderName == "System.Data.OleDb")
                {
                    System.Web.UI.Page page = new System.Web.UI.Page();
                    str2 = str.Substring(str.IndexOf("App_Data"));
                    str = page.Server.MapPath(str2);
                    str3 = str3.Replace(str2, str);
                    dbConnection.ConnectionString = str3;
                }
                else
                {
                    dbConnection.ConnectionString = setting.ConnectionString;
                }

这样就能在配置文件里 使用相对路径正常访问了

相关文章:

  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-01-14
  • 2022-12-23
  • 2021-10-21
  • 2022-01-23
猜你喜欢
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案