且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server Express连接到.mdf文件

更新时间:2022-11-25 13:01:52

我借助Yair M对

I managed to solve this problem with the aid of an answer by Yair M to this question.

我首先使用控制面板->程序和工具,以物理方式卸载了与我的SQL Server 2012版本相对应的v11.0之外的所有版本的LocalDb.功能.

I first physically uninstalled all versions of LocalDb aside from the v11.0 one which corresponded to my version of SQL Server 2012, using the Control Panel --> Programs & Features.

然后使用命令行,我发出了以下命令:

Then using the command line, I issued the following commands:

sqllocaldb删除"v11.0"

sqllocaldb delete "v11.0"

sqllocaldb创建"v11.0"

sqllocaldb create "v11.0"

这解决了当我尝试注册新用户时擦拭而不重新创建基于文件的LocalDb实例的问题.

This solved the issue where the file based instance of LocalDb was being wiped and not re-created when I tried to register a new user.

此时,我可以注册一个新用户,而不会出现任何错误消息.但是,我想离开LocalDB.

At this point I could register a new user without any error messages. However, I wanted to move away from LocalDB.

因此,我在SSMS中创建了一个空数据库,并将.mdf文件附加到该数据库.我更新了连接字符串,以使用实际的数据库和集成安全性(用于本地开发).运行该应用程序时出现一些权限错误,但能够通过创建一个新用户并赋予其读写访问权限来解决此问题.

So, I created an empty database in SSMS and attached the .mdf file to it. I updated my connection string to use an actual DB and Integrated Security (for local development). I got some permissions errors when running the app, but was able to remedy this by creating a new user and giving it read and write access.

<add name="DefaultConnection" 
  connectionString="Initial Catalog=DevilsTower;Data Source=Development;Integrated Security=SSPI;" 
    providerName="System.Data.SqlClient" />