Windows Form connection string

nationaltravel
nationaltravel used Ask the Experts™
on
When using the following connection string on my windows application:
sqlconnect1 = "Data Source=.\SQLEXPRESS;AttachDbFilename='" & Environment.CurrentDirectory.ToString & "Database1.mdf';Integrated Security=SSPI

I receive the following error:
An attempt to attach an auto-named database for file C:\Documents and Settings\JayDee\My Documents\Visual Studio 2005\Projects\StatPro\StatPro\bin\DebugDatabase1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I am trying to complete my project to deploy to other workstations.  Does anyone know why I receive this error?  
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
try replacing & Environment.CurrentDirectory.ToString &
with hard coded path. Not sure you can use that in this context
I’m a software engineer, tech enthusiast and UI/UX lover.
Commented:
the path is wrong, from the error
the application is trying to access the file
"C:\Documents and Settings\JayDee\My Documents\Visual Studio 2005\Projects\StatPro\StatPro\bin\DebugDatabase1.mdf"
which i think should be this
"C:\Documents and Settings\JayDee\My Documents\Visual Studio 2005\Projects\StatPro\StatPro\bin\Debug\Database1.mdf"
change your code to
sqlconnect1 = "Data Source=.\SQLEXPRESS;AttachDbFilename='" & Environment.CurrentDirectory.ToString & "\\Database1.mdf';Integrated Security=SSPI

Author

Commented:
waaromikniet:

coding it with a hard coded path will not allow me to deploy on other workstations.  In other words, I want to give the user the ability to install the software whereever they choose.

Author

Commented:
akindelu:

I see that error as you mentioned.

This corrects the problem initially, but the next time I use the same connection string, I receive the same error, even though I have corrected the error in all of my connection strings.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial