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" />
要更改connectionsinfo,请使用以下代码:
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
Assemblies EntityFramework和EntityFramework.SqlServer与DAL-Class位于同一文件夹中,EntityFramework.SqlServer使用EntityFramework.dll构建
有人可以帮助我吗?