实体框架EntityConnection元数据问题

发布于 2024-09-09 11:35:17 字数 1754 浏览 3 评论 0原文

我们正在尝试动态构建 EntityConnection,以便不同的用户连接到运行时确定的不同数据库。为此,我们正在测试此处的代码: http://msdn .microsoft.com/en-us/library/bb738533.aspx。我们在下面实现了这一点:

' Specify the provider name, server and database.
Dim providerName As String = "System.Data.SqlClient"
Dim serverName As String = "OurDBServerName"
Dim databaseName As String = "OurDBName"

' Initialize the connection string builder for the
' underlying provider.
Dim sqlBuilder As New SqlConnectionStringBuilder

' Set the properties for the data source.
sqlBuilder.DataSource = serverName
sqlBuilder.InitialCatalog = databaseName
sqlBuilder.IntegratedSecurity = False
sqlBuilder.UserID = "OurAppUserName"
sqlBuilder.Password = "OurPassword"

' Build the SqlConnection connection string.
Dim providerString As String = sqlBuilder.ToString

' Initialize the EntityConnectionStringBuilder.
Dim entityBuilder As New EntityConnectionStringBuilder

'Set the provider name.
entityBuilder.Provider = providerName

' Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString

' Set the Metadata location to the current directory.
entityBuilder.Metadata = "res://*/NotaModel.csdl|" & _
                         "res://*/NotaModel.ssdl|" & _
                         "res://*/NotaModel.msl"

Console.WriteLine(entityBuilder.ToString)

Using conn As EntityConnection = New EntityConnection(entityBuilder.ToString)
    conn.Open()
    Console.WriteLine("Just testing the connection.")
    conn.Close()
End Using

当 conn.Open() 运行时,会抛出错误:“无法加载指定的元数据资源。”这似乎表明一个或多个“res://*...”引用是错误的。我已经确认该项目确实包含这些文件(在 bin/debug 文件夹下)。我们在这里缺少什么 - 有什么想法吗?

谢谢

We are trying to build an EntityConnection dynamically so that different users are connecting to differnet databases determined at run-time. In order to do this we are testing the code found here: http://msdn.microsoft.com/en-us/library/bb738533.aspx. We have implemented this below:

' Specify the provider name, server and database.
Dim providerName As String = "System.Data.SqlClient"
Dim serverName As String = "OurDBServerName"
Dim databaseName As String = "OurDBName"

' Initialize the connection string builder for the
' underlying provider.
Dim sqlBuilder As New SqlConnectionStringBuilder

' Set the properties for the data source.
sqlBuilder.DataSource = serverName
sqlBuilder.InitialCatalog = databaseName
sqlBuilder.IntegratedSecurity = False
sqlBuilder.UserID = "OurAppUserName"
sqlBuilder.Password = "OurPassword"

' Build the SqlConnection connection string.
Dim providerString As String = sqlBuilder.ToString

' Initialize the EntityConnectionStringBuilder.
Dim entityBuilder As New EntityConnectionStringBuilder

'Set the provider name.
entityBuilder.Provider = providerName

' Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString

' Set the Metadata location to the current directory.
entityBuilder.Metadata = "res://*/NotaModel.csdl|" & _
                         "res://*/NotaModel.ssdl|" & _
                         "res://*/NotaModel.msl"

Console.WriteLine(entityBuilder.ToString)

Using conn As EntityConnection = New EntityConnection(entityBuilder.ToString)
    conn.Open()
    Console.WriteLine("Just testing the connection.")
    conn.Close()
End Using

When the conn.Open() is run an error is thrown: "Unable to load the specified metadata resource." It seems to indicate that one or more of the "res://*..." references is wrong. I have confirmed that the project does indeed contain these files (under the bin/debug folder). What are we missing here - any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

不醒的梦 2024-09-16 11:35:17

是的,res:// 部分是错误的。查看 Reflector 中(程序集内)而不是本地文件系统上的资源名称,看看它们应该是什么。

Yes, the res:// part is wrong. Look at the resource names in Reflector (inside the assembly), not on your local filesystem, to see what they should be.

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