我的 SQL Server Express 似乎已经疯了,有时会安装数据库,而其他则不会
我不确定到底发生了什么,因为我无法在两者之间建立严格的线性相关性 事件。但在下面您会发现我的连接字符串,有时它有效,其他时候当我打开我正在构建的应用程序/项目(未进行任何更改)时它不起作用,并给我带来各种错误和原因。
<add name="EFDbContext"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\EFDbContext.mdf;MultipleActiveResultSets=true;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
错误包括:
无法完成操作。提供的 SqlConnection 未指定初始目录。
或者
说 Amin-PC\Admin 没有访问权限(我已登录 admin)
另外,当我尝试添加新连接时,它会告诉我我没有访问权限或数据库已存在,或者只是正常添加!
我尝试以管理员身份明确启动 Visual Studio,这似乎有助于解决拒绝访问数据库问题。
基本上我不知道到底发生了什么。
最近开始使用 .net,对 ASP.NET MVC 框架进行编码很容易,直到我开始与底层 ASP.NET 基础设施、连接字符串、过时的(中午实体框架就绪)会员提供程序等进行交互。
现在不这样做了解与 VS2010 一起安装很长时间的 SQL Server Express 版本的情况。
I am not sure what's going on exactly as I can't establish a strict linear correlation between
events. But below you'll find my connection string, at times it works, other times when I open the app/project I am building (no changes made) it doesn't and gives me various errors and reasons.
<add name="EFDbContext"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\EFDbContext.mdf;MultipleActiveResultSets=true;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
Errors include:
Unable to complete operation. The supplied SqlConnection does not specify an initial catalog.
or
saying Amin-PC\Admin has no access rights (I am logged in admin)
Also when I try to add a new connection at times it will tell me I have no access rights or database already exists or just adds it normally!
I tried explicitly starting visual studio as administrator and this seemed to help with the denied access to the db issue.
Basically I don't know what the heck's going on.
Have recently started with .net and it has been easy coding for asp.net mvc framework until I got to interacting with underlying asp.net infrastructure, connection strings, outdated (noon-entity framework ready) membership provider etc.
And now don't know what's going on with the SQL Server Express edition that gets installed a long with VS2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的建议是:由于您已经安装了服务器实例 (
.\SQLEXPRESS
) - 将您的数据库附加到 SQL Server Express 实例,然后在其数据库名称下使用它们(而不是使用不稳定的数据库)AttachDbFileName=
方法)。因此:
您的连接字符串然后看起来像:
我发现这种方法通常更可靠和可预测 -
AttachdbFileName=
和User Instance=true
应该更容易,但往往是比其他任何事情都更令人困惑......My recommendation would be: since you already have a server instance (
.\SQLEXPRESS
) installed - attach your databases to the SQL Server Express instance, and then use them under their database name (instead of using the shakyAttachDbFileName=
method).So:
Your connection string would then look something like:
I find this method is typically much more reliable and predictable - the
AttachdbFileName=
andUser Instance=true
are supposed to be easier, but tend to be more confusing that anything else....请参阅此处的 SQL Server 连接字符串示例。
Refer to SQL Server connection string samples here.