Проблема метаданных объект-структуры объекта
-
15-09-2020 - |
Вопрос
Мы пытаемся динамически построить 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).Что мы там не хватаем - любые идеи?
Спасибо
Решение
Да, часть генеракодицетагкода неверна.Посмотрите на имена ресурсов в отражателе (внутри сборки), а не на местной файловой системе, чтобы увидеть, что они должны быть.