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

Re: SQL Server Express Error on Connection by William

William
Wed Nov 22 14:25:34 CST 2006

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

"elziko" <elziko@yahoo.co.uk> wrote in message
news:uXS4WZjDHHA.1220@TK2MSFTNGP04.phx.gbl...
> 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
>
>
>



Re: SQL Server Express Error on Connection by anu

anu
Thu Nov 23 07:37:41 CST 2006

can we connect sql server to java how

"elziko" <elziko@yahoo.co.uk> wrote in message
news:uXS4WZjDHHA.1220@TK2MSFTNGP04.phx.gbl...
> 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
>
>
>



Re: SQL Server Express Error on Connection by Cor

Cor
Thu Nov 23 23:23:44 CST 2006

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

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

Cor

"anu" <abc@yahoo.com> schreef in bericht
news:e4atRSwDHHA.3836@TK2MSFTNGP02.phx.gbl...
> can we connect sql server to java how
>
> "elziko" <elziko@yahoo.co.uk> wrote in message
> news:uXS4WZjDHHA.1220@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>>
>>
>
>