数据库连接错误“文件正在使用"; [英] Database Connection Error "file in use"
问题描述
我正在将Visual Studio 2010 C#Express和SQL Server Management Studio与SQL Server 2012一起使用 尝试将数据库连接到Windows窗体项目时出现错误.
I am using Visual Studio 2010 C# Express and SQL Server Management Studio with SQL Server 2012 I am getting an error when I try to connect a database to my Windows forms project.
"This file is in use. Enter a new name or
close the file that is open in another program"
我在网上闲逛,试图找到解决方案,但没有一个有效.因此,我决定创建一个全新的数据库和一个全新的项目.但是我仍然会收到错误消息!
I poked around online to try to find a solution but none worked. So i decided to create a brand new database and a brand new project. But I still get the error!
这是我使用的步骤:
- 首先我连接到本地托管的服务器
- 然后我右键单击
Databases
并选择New Database
并将其命名为school
- 然后我右键单击新数据库上的
tables
文件夹,然后选择new table
- 我添加了这些表
student, course, enrolled
- 最后我把一些假的东西扔进去了
- First I connected to my locally hosted server
- then i right-clicked on
Databases
and selectedNew Database
and named itschool
- then i right clicked the
tables
folder on my new database and selectednew table
- I added thes tables
student, course, enrolled
- finally i threw some bogus entries into it
现在我跳到VS
- 我选择
New Project
然后选择Windows Forms Application
并将其命名为Registrar
- 然后单击
add new data source
- 在
Choose a data source type
窗口中选择database
- 然后在
Choose a Database Model
窗口中选择Dataset
- 然后单击
New Connection
,将数据源更改为Microsoft SQL Server Database File
,浏览到"SQLEXPRESS"文件夹中的DATA文件夹,当我单击"school.mdf"文件时,出现上述错误.
- I select
New Project
thenWindows Forms Application
and name itRegistrar
- then i click
add new data source
- select
database
in theChoose a data source type
window - then i select
Dataset
in theChoose a Database Model
window - then I click
New Connection
I change the DataSource toMicrosoft SQL Server Database File
browse to the DATA folder inside my 'SQLEXPRESS' folder and when i click the 'school.mdf' file i get the above error.
任何帮助将不胜感激.
推荐答案
您的school.mdf附加在您的SQL Server 2012中.您需要将其分离.
Your school.mdf is attached in your SQL Server 2012. You need to detach it.
转到您的SQL Server Management Studio,右键单击学校",任务",分离".
Go to your SQL Server Management Studio, Right-Click on School, Tasks, Detach.
除非已分离,否则它将由SQL Server Management Studio使用.
Unless it is detached, it will be in use by the the SQL Server Management Studio.
这篇关于数据库连接错误“文件正在使用";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!