我的 SQL Server Express 似乎已经疯了,有时会安装数据库,而其他则不会

发布于 2024-12-18 09:12:01 字数 869 浏览 1 评论 0原文

我不确定到底发生了什么,因为我无法在两者之间建立严格的线性相关性 事件。但在下面您会发现我的连接字符串,有时它有效,其他时候当我打开我正在构建的应用程序/项目(未进行任何更改)时它不起作用,并给我带来各种错误和原因。

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-12-25 09:12:01

我的建议是:由于您已经安装了服务器实例 (.\SQLEXPRESS) - 将您的数据库附加到 SQL Server Express 实例,然后在其数据库名称下使用它们(而不是使用不稳定的数据库) AttachDbFileName= 方法)。

因此:

  • 启动 SQL Server Management Studio Express
  • 找到您想要
  • 使用的 MDF 文件 Server >附加数据库以将 MDF/LDF 附加到服务器 -
  • 从那时起为其指定有意义的名称 - 在服务器上使用数据库,并且不要即时附加 MDF...

您的连接字符串然后看起来像:

server=.\SQLEXPRESS;Database=YourEFDatabaseName;Integrated Security=True

我发现这种方法通常更可靠和可预测 - 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 shaky AttachDbFileName= method).

So:

  • launch your SQL Server Management Studio Express
  • find your MDF files you want
  • use Server > Attach Database to attach the MDF/LDF to the server - give it meaningful name
  • from that point on - use the database on the server and don't attach MDF's on the fly....

Your connection string would then look something like:

server=.\SQLEXPRESS;Database=YourEFDatabaseName;Integrated Security=True

I find this method is typically much more reliable and predictable - the AttachdbFileName= and User Instance=true are supposed to be easier, but tend to be more confusing that anything else....

无言温柔 2024-12-25 09:12:01

请参阅此处的 SQL Server 连接字符串示例。

Refer to SQL Server connection string samples here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文