此代码工作正常:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=myDB;Integrated Security=SSPI;
" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
但这段代码不起作用:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=.\MSSQLSERVER2008; Initial Catalog=myDb;Integrated Security=SSPI;User ID=useradmin; Password=pass; " providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\MSSQLSERVER2008; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
第二个代码必须在具有 MSQSERVER2008 实例的远程服务器上运行,并且在加载页面时,会出现以下消息:
从数据库获取提供者信息时出错。这可能是由 Entity Framework 使用不正确的连接字符串引起的。检查内部异常以获取详细信息并确保连接字符串正确。