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
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