使用下面的连接字符串,一切都很正常。
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />我最近在本地计算机上安装了SQL Server 2012 Express进行测试,但无法建立连接。这是我使用Windows身份验证的连接字符串。
<add name="ApplicationServices" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />我完全是个菜鸟,尽了最大的努力去搜索论坛,但是我不能把我的解决方案推迟到“标题相似的问题”部分。任何帮助都是非常感谢的。
发布于 2012-08-01 20:56:38
EntityFramework代码首先在app.config或web.config文件中使用defaultConnectionFactory,它将自动连接到.\SQLEXPRESS。此配置如下所示:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
</entityFramework>如果您首先使用EF代码,那么您可能有一个从DbContext派生的类用作上下文。根据设计,EntityFramework将查找与您的上下文类同名的连接字符串,并使用该字符串而不是defaultConnectionFactory。这就是我使用它的方式:
<connectionStrings>
<add name="ObjectContext"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=My.Db.Name; Integrated Security=True; MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>我的建议是检查EF没有使用它的defaultConnectionFactory,甚至通过添加以上下文命名的连接字符串来强制覆盖它。您还应该查看this blog article,其中提供了有关EF配置文件的详细信息。
发布于 2012-04-27 20:36:40
您确定连接的这部分是正确的吗?"Data Source=.\SQLEXPRESS Name;
我没有使用过SQL Server 2012,但尝试删除名称文本。
发布于 2013-04-11 03:12:40
这对我很有效
add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS;
Initial Catalog=Movies;
Integrated Security="True" providerName="System.Data.SqlClient"我正在学习这篇教程,我必须把它做出来。MovieDBContext是在mvc应用程序模型的代码中创建的。
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}这会使集成开发环境自动创建控制器类,但在我在web.config文件中获得正确的连接字符串之前,它不会工作。
https://stackoverflow.com/questions/10339163
复制相似问题