将新数据库文件附加到Windows窗体应用程序时出现问题。 [英] Problem attaching a new database file to a windows form application.

查看:64
本文介绍了将新数据库文件附加到Windows窗体应用程序时出现问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用SSMS创建了一个新的数据库文件,然后尝试使用Data Source应用程序将其附加到新的Windows Form Application。当我浏览到数据文件(.mdf)时,我收到一条错误消息,指出我没有权限使用此文件。所以,我进去并更改了数据文件的权限。当我想要再次附加新数据库时,我收到另一条错误消息正在使用的文件。输入新名称或关闭在另一个程序中打开的文件。在调查中我发现该文件在SQL Server中是打开的,我不知道如何关闭它。我在Windows 10 Pro上使用SQL Server Express 2014,Visual Studio Community 2017 Visual Basic。我如何克服这个?



我尝试过:



正如我所说,我不知道如何解决它。

I just created a new database file using SSMS and then tried to attach it to a new Windows Form Application using the Data Source app. When I Browse to the data file (.mdf) I got an error message stating I didn't have permission to use this file. So, I went in and changed the permissions on the data file. The when I want back to again attach the new database I get another error message, "File in use. Enter a new name or close the file that's open in another program." In investigating I find that the file is open in the SQL Server and I have no idea how to close this. I am using SQL Server Express 2014, Visual Studio Community 2017 Visual Basic on Windows 10 Pro. How do I overcome this?

What I have tried:

Just what I've stated, I have no Idea how to fix it.

推荐答案

附加数据库是SQL的一个特殊模式,其中一个新的服务器实例是分拆来管理那个DB文件,它只用于开发,以便您的代码可以;崩溃任何其他数据库访问。由于这个原因,仅在Express版本中,它不能在完整SQL Server中使用。

当您附加数据库时,新的SQL Server引擎实例将被启动并控制文件。在文件分离或实例关闭之前,该文件正在使用中并将保持这种状态。在使用它的时候,SQL服务器对文件有一个独占锁,你无法在不同的应用程序中打开它。

我强烈建议你将数据库导入SQL,并让它完全管理它而不是附加。
Attaching databases is a special "Mode" of SQL where a new instance of the server is "spun off" to look after that one DB file, and it intended only for development so that your code can;t crash out any other database access. It isn't available in "full" SQL Server for that very reason, just in the Express edition.
When you attach a DB, a new instance of SQL Server engine is spun up and takes control of the file. Until the file is detached or the instance closed, the file is in use and will remain that way. While it's in use, SQL server has an exclusive lock on the file and you cannot open it in a different application.
I would strongly suggest that you import your DB to SQL, and let it manage it completely instead of attaching.


这篇关于将新数据库文件附加到Windows窗体应用程序时出现问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆