我们正在尝试动态构建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文件夹下)。我们在这里缺少什么 - 任何想法?

感谢

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top