2

I am having trouble connecting to a database I created in SSMS. Keep in mind this is my first time working with databases. All I've done in this database is create some tables and add a few records. What I need to do is connect to this database in Visual Studio 2015. However, when I try to add a connection to a Microsoft SQL Server Database File to my windows forms application it says the file is in use and will not let me select it. When I select a different database file I created in SSMS and test the connection it tells me this database file is not compatible with the current instance of SQL Server. To resolve this issue, you must upgrade the database file by creating a new connection or modify the existing connection to this database file. Now in order to upgrade a database file, according to MS documentation, is to attach the database. But when I right click the "Database" node in SSMS and click attach and try to add either of the two database .mdf files from earlier, it gives me this error:

TITLE: Microsoft SQL Server Management Studio
------------------------------

Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. 
(Microsoft.SqlServer.ConnectionInfo)

------------------------------

CREATE FILE encountered operating system error 32(The process cannot access the file 
because it is being used by another process.) while attempting to open or create the 
physical file 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\Mestek Database.mdf'. 
(Microsoft SQL Server, Error: 5123)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=12.00.2000&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476

I ran this query on the database which I guess returns any process using the database.

SELECT * FROM sysfiles

But this just returns the file path and name of the .mdf file and log file.

1

Do not fear everyone, I fixed my problem. What I had to do was detach the databases that I needed so that they were no longer being used by SSMS. This got rid of the error I was having and allowed me to add a connection to the data source in visual studio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.