enter code here
我在 VS2010 中编写了一个 .NET 4.0 应用程序并将使用 EF6。这是我的 App.Config:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral" requirePermission="false" />
要更改连接信息,我使用以下代码:
Public ReadOnly Property SqlConnectionString As String
Get
With sqlBuilder
.DataSource = ServerName
.InitialCatalog = DatabaseName
If DatabaseUserName.Length = 0 Then
.IntegratedSecurity = True
Else
.IntegratedSecurity = False
.UserID = DatabaseUserName
.Password = DatabasePassword
End If
sqlBuilder.MultipleActiveResultSets = True
End With
Return sqlBuilder.ToString & ";App=EntityFramework"
End Get
End Property
Public ReadOnly Property EntityConnectionString As String
Get
Dim _metaData As String = ""
With entityBuilder
.Provider = ProviderName
.ProviderConnectionString = SqlConnectionString
_metaData = "res://" & DatabaseModelAssembly & "/" & DatabaseModelName & ".csdl|"
_metaData = _metaData & "res://" & DatabaseModelAssembly & "/" & DatabaseModelName & ".ssdl|"
_metaData = _metaData & "res://" & DatabaseModelAssembly & "/" & DatabaseModelName & ".msl"
.Metadata = _metaData
End With
Return entityBuilder.ToString
End Get
End Property
Public Function ConnectionTest() As Boolean
Try
Dim conn As New EntityConnection(EntityConnectionString)
conn.Open()
Console.WriteLine("Just testing the connection.")
conn.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
如果我尝试使用“打开”检查连接,则会出现以下错误:
Data.SqlClient' ADO.NET provider. Make sure the provider is registered in the 'entityFramework' section of the application config file
程序集 EntityFramework 和 EntityFramework.SqlServer 与 DAL-Class 位于同一文件夹中,并且 EntityFramework.SqlServer 是使用 EntityFramework.dll 构建的
有人可以帮助我吗?