In .NET, you can open a SQL Express database simply by attaching the database MDF file in the connection string (that is, you don't have to have any server software installed, it just attaches to the MDF file on the fly).
在.NET中,只需将数据库MDF文件附加到连接字符串中即可打开SQL Express数据库(也就是说,您不必安装任何服务器软件,只需动态附加到MDF文件)。
When an application does this, does it obtain an exclusive lock on the database file? Or, can a second application also attach to and open the MDF file in this same way, and query the database while program #1 is using it?
当应用程序执行此操作时,它是否获得数据库文件的独占锁定?或者,第二个应用程序是否也可以以相同的方式附加和打开MDF文件,并在程序#1使用它时查询数据库?
1 个解决方案
#1
You are correct, only a single connection can be open to the MDF at a time.
您是对的,一次只能打开一个MDF连接。
This can get really annoying when you open the database through your server explorer in Visual Studio, and then try to run your application.
当您通过Visual Studio中的服务器资源管理器打开数据库,然后尝试运行您的应用程序时,这会非常烦人。
I've caught myself doing that too many times to count, and I always invariably end up just attaching the mdf to my sql server instance.
我发现自己做了太多次计算,我总是最终只是将mdf附加到我的sql server实例。
#1
You are correct, only a single connection can be open to the MDF at a time.
您是对的,一次只能打开一个MDF连接。
This can get really annoying when you open the database through your server explorer in Visual Studio, and then try to run your application.
当您通过Visual Studio中的服务器资源管理器打开数据库,然后尝试运行您的应用程序时,这会非常烦人。
I've caught myself doing that too many times to count, and I always invariably end up just attaching the mdf to my sql server instance.
我发现自己做了太多次计算,我总是最终只是将mdf附加到我的sql server实例。