如何在同一项目中使用 EF 连接字符串和 ADO.Net 连接字符串

How to use EF connection string and ADO.Net connection string in same project

在我使用的普通 EF 连接字符串中是这样的:

<add name="NorthwindEntities" 
     connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=******;initial catalog=******;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

但是当我尝试在当前项目中添加Ado.Net会员系统时,连接字符串必须是这样的:

<add name="MembershipEntities" 
     connectionString="data source=*****;initial catalog=*****;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" 
     providerName="System.Data.EntityClient" />

如何处理这种情况?

为了其他人的利益,我将这个问题与解决方案结合起来。

问题,在此处添加连接字符串名称 (connectionStringName):

<membership>
          <providers>
              <clear/>
              <add name="AspNetSqlMembershipProvider"
                  type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                  connectionStringName="NorthwindEntities"
                  enablePasswordRetrieval="false"
                  enablePasswordReset="true"
                  requiresQuestionAndAnswer="true"
                  applicationName="/"
                  requiresUniqueEmail="true"
                  passwordFormat="Hashed"
                  maxInvalidPasswordAttempts="5"
                  minRequiredPasswordLength="3"
                  minRequiredNonalphanumericCharacters="0"
                  passwordAttemptWindow="10"
                  passwordStrengthRegularExpression="" />
          </providers>
      </membership>

它带来了这个错误:“不支持关键字:元数据” 要解决此错误,我们需要在节点中添加另一个连接字符串。并更改连接字符串名称 connectionStringName="MembershipEntities"

<connectionStrings>
    <add name="NorthwindEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*****;initial catalog=*****;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="MembershipEntities" connectionString="data source=*****;initial catalog=*****;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.EntityClient" />
  </connectionStrings>