CSLA 3.6 - 在配置文件中找不到数据库名称

发布于 2024-07-16 01:47:43 字数 1198 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮光之海 2024-07-23 01:47:43

确保您使用正确的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文