SQL Server Express Error on Connection

E

elziko

My application uses the following code to attach and open a connection to an
SQL Server Express Database:

Dim conDatabase As New SqlConnection("Data
Source=.\SQLEXPRESS;AttachDbFilename="c:\database.mdf";Integrated
Security=True;Connect Timeout=30;User Instance=True")
conDatabase.Open()

The first time this works fine, then my application detatches the database
from SQL Server Express using SSEUTIL.

Then the user tries to attach and connect to another database (using the
same code as above) and I get this error:

A first chance exception of type 'System.Data.SqlClient.SqlException'
occurred in System.Data.dll
System.Data.SqlClient.SqlException: Unable to open the physical file
"c:\anotherpath\database.mdf". Operating system error 32: "32(error not
found)".
An attempt to attach an auto-named database for file
c:\anotherpath\database.mdf failed. A database with the same name exists, or
specified file cannot be opened, or it is located on UNC share.

Now the databases do have the same filename (in a different folder) but I
have checked that after the first database is detached, that SSEUTIL reports
that only the orginal system databases are attcahed by using "SSEUTIL -l".
So, no, a database with the same name is not attached.

The database is not located on a UNC share.

Then if I re-write my code to continue calling the Open method of the
connection until it is successful, it eventually works. This typically takes
around 5000 attempts.

Can anyone give me any ideas about what may be causing this problem?

TIA
 
W

William \(Bill\) Vaughn

I don't really understand what you're trying to accomplish. When you use the
User Instance option, SQL Server (and the provider) copy the mdf to the
user's directory (along with Master, Model etal). Why is it that you want to
open additional databases? Why detach? When the Open fails, is the mdf in
the location specified? No, it should not be on the net somewhere...`

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
 
C

Cor Ligthert [MVP]

As Java has AdoNet included, probably yes, otherwise I would not know.

Written from the AdoNet newsgroup were this message was sent to.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top