数据库连接错误“文件正在使用"; [英] Database Connection Error "file in use"

查看:304
本文介绍了数据库连接错误“文件正在使用";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将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 selected New Database and named it school
  • then i right clicked the tables folder on my new database and selected new 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 then Windows Forms Application and name it Registrar
  • then i click add new data source
  • select database in the Choose a data source type window
  • then i select Dataset in the Choose a Database Model window
  • then I click New Connection I change the DataSource to Microsoft 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屋!

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