CSLA 3.6 - 在配置文件中找不到数据库名称
我正在使用 CSLA 3.6
我不断收到错误:
DataPortal.Fetch 失败(在配置文件 (AdventureWorksLT) 中找不到数据库名称)
我的 Dataportal_Fetch 代码如下所示:
Private Overloads Sub DataPortal_Fetch(ByVal criteria As SingleCriteria(Of Customer, Integer))
Using ctx = ContextManager(Of DalLinq.AdventureWorksDataContext).GetManager(DalLinq.Database.AdventureWorksLTConnectionString)
Dim data = (From p In ctx.DataContext.Customers Where p.CustomerID = criteria.Value Select p).Single
LoadProperty(Of Integer)(CustomerIdProperty, data.CustomerID)
LoadProperty(Of String)(CompanyNameProperty, data.CompanyName)
End Using
End Sub
我的 Database.vb 文件如下所示:
Public Class Database
Public Const AdventureWorksLTConnectionString As String = "AdventureWorksLT"
End Class
我的 App.Config 文件包含以下内容(由于 stackoverflow,用 ( 和 ) 替换 < 和 > 字符:
(connectionStrings)
(add name="AdventureWorksLT" connectionString="Data Source=(local);Initial Catalog=AdventureWorksLT;User Id=AdvWorks;Password=UserPW;"
providerName="System.Data.SqlClient" /)
(/connectionStrings)
我缺少什么?
谢谢!
I'm using CSLA 3.6
I keep getting the error:
DataPortal.Fetch failed (Database name not found in config file (AdventureWorksLT))
My Dataportal_Fetch code looks like this :
Private Overloads Sub DataPortal_Fetch(ByVal criteria As SingleCriteria(Of Customer, Integer))
Using ctx = ContextManager(Of DalLinq.AdventureWorksDataContext).GetManager(DalLinq.Database.AdventureWorksLTConnectionString)
Dim data = (From p In ctx.DataContext.Customers Where p.CustomerID = criteria.Value Select p).Single
LoadProperty(Of Integer)(CustomerIdProperty, data.CustomerID)
LoadProperty(Of String)(CompanyNameProperty, data.CompanyName)
End Using
End Sub
My Database.vb file looks like this:
Public Class Database
Public Const AdventureWorksLTConnectionString As String = "AdventureWorksLT"
End Class
And my App.Config file contains the following(Substitutes < and > character with ( and ) due to stackoverflow :
(connectionStrings)
(add name="AdventureWorksLT" connectionString="Data Source=(local);Initial Catalog=AdventureWorksLT;User Id=AdvWorks;Password=UserPW;"
providerName="System.Data.SqlClient" /)
(/connectionStrings)
What am I missing?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您使用正确的 app.config 文件。 ConfigurationManager 查看当前正在运行的项目(即您的测试项目和/或您的 Windows 窗体/控制台应用程序)。
ContextManager 的默认行为是使用 ConfigurationManager 查找命名连接字符串,除非您将 true 传递给 ContextManager 中的第二个参数,然后它将仅使用提供的字符串作为连接字符串。
Make sure that you are using the correct app.config file. The ConfigurationManager looks at the current running project (i.e. your test project and/or your windows forms/console app).
The default behavior for the ContextManager is to use ConfigurationManager to look for the named connection string unless you pass true to the second parameter in the ContextManager, then it will just use the provided string as the connection string.