views:

673

answers:

1

Hi, I'm using VB 2008 Express for our College Project. I'm also running SQL Server 2008 Express and have installed SQL Server Management Studio and used it to create my database.

Both software have been installed and running locally. I'm trying to connect to the database from VB 2008 Express. Database connection wizard have 3 options:

  1. connecting to Access db
  2. connecting to SQL Server 3.5 compact db and
  3. connecting to SQL Server db file.

There are no problems connecting to the first two but when I try to connect to my SQL server DB file (.mdf) it throws the following error ("Unable to open the physical file .... Operating system error 32:(failed to retrieve text for this error. reason:1815.......an attempt to attach an auto-named database for file ...... .mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share")

I appreciate if anyone who had the same experience and overcome the problem could point me in the right direction.

Thanks very much. Little Critter.

+2  A: 

You need to detach your database from the server. Since you created the file there it is already running on the SQL Express server. Operating System Error 32 is a sharing violation and it means that the file is in use.

Try this:

  1. Open Sql Express 2008 Managment Studio and find your database in the Object Explorer tree.
  2. Right click on your database, choose tasks, and then select "Detach"
  3. When the "Detach Database" dialog appears, select the checkbox that says "Drop Connections"
  4. Click ok.

Your database should detach from the database server. Now the server will no longer bring that database up automatically and you should be able to get exclusive access to it.

Note that if you want to make more edits to the MDF you will have to reattach the database or you will need to use the tools built into VB 2008 Express. Because of this most people would choose to leave the database attached and not run it as a "User Instance". Check out this link for alternative ways to get to your data: How to: Access and Initialize Server Explorer/Database Explorer.

Anyway, you may have your reasons for setting it up this way. The steps outlined above should fix you up. Good luck with your project!

magnifico