【发布时间】:2013-08-31 07:20:44
【问题描述】:
我的项目具有 3 层结构 DataAccessLayer、BusinessLogicLayer 和网站。
在我的 DataAccessLayer 中,我使用了 F# 库项目,通过 app.config 文件访问连接字符串
F# 代码 -
type dbSchema = SqlDataConnection<"","MyConnection">
let connectionString = System.Configuration.ConfigurationManager.ConnectionStrings. ["MyConnection"].ConnectionString
App.config 代码 -
<connectionStrings>
<add name="MyConnection" connectionString="Data Source=MyServer;Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=xyz;" providerName="System.Data.SqlClient"/>
</connectionStrings>
现在我已经给出了这个dll在网站BusinessLogic和网站项目中的引用。
我正在调用BusinessLogicLayer的一个函数来获取数据-
var MyDataList = BusinessLogic.GetAllData().ToList();
现在的问题是,网站正在 app.config 文件中搜索连接字符串,而不是 web.config。我希望它从 web.config 中获取连接字符串
【问题讨论】:
-
您的 app.config 在您的“DataAccessLayer”项目中吗?
-
F# 项目是否在它自己的进程中运行?如果一切都从 IIS 运行,它应该从 web.config 读取。您确定您的 web.config 中有
<connectionStrings> <add name="MyConnection"部分吗? -
是的,该部分已添加到 web.config 中
-
我怀疑这不起作用,因为 F# 编译器需要在编译时而不是运行时访问连接字符串。但我可能错了。
-
它与在 web 应用程序目录中添加 app.config 一起工作。但不是 web.config。