OK - I have seen lots posted on this, but the behavior is very strange, and I am trying to understand:
I am using Visual Basic 2003 with SQLEXPRESS 2005 to connect to a database and to develop a desktop application. My connection string is: Conn_Str = "Data Source=.\SQLExpress;AttachDbFilename=" & _
Directory.GetCurrentDirectory & "\CWW.mdf;" & _
"Trusted_Connection=Yes;"
I get the following error:
"An attempt to attach an auto-named database for file C:\Documents and Settings\Brian\My Documents\Compressor Program Development\bin\CWW.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
However, if I copy the database to anywhere else on the "c:\" drive, the connection works, as in the following:
Conn_Str = "Data Source=.\SQLExpress;AttachDbFilename=" & _
"C:\temp\CWW.mdf;" & _
"Trusted_Connection=Yes;"
What I have found is that ist works everywhere on my computer except in the following location:
"c:\documents and settings\Brian", which includes My Documents, Desktop folders.
Why is this?
Any help would be great - I can work around this by moving my development folder to the "c:\" drive. Since my ultimate application directory will be the "Program Files" directory I should be fine.
hi,
bridress wrote:
Conn_Str = "Data Source=.\SQLExpress;AttachDbFilename=" & _
Directory.GetCurrentDirectory & "\CWW.mdf;" & _
"Trusted_Connection=Yes;"
did you try "AttachDbFilename=|DataDirectory|\CWW.mdf;" ?
regards
|||Thanks for the response -Yes I did - I even tried the following to shift the default DataDirectory:
AppDomain.CurrentDomain.SetData("DataDirectory", Directory.GetCurrentDirectory)
Proj_ConnStr="DataSource=.\SQLExpress;AttachDbFilename=|DataDirectory|\CWW.mdf; _ Trusted_Connection=Yes;"
I still had no success. It seems I should be able to put the db file in any directory I choose and not be restricted like this?
|||
hi,
please verify the Windows account running the SQLExpress is granted enought NTFS permissions on the specified path...
regards
|||The first time you run your code it attaches the database and used the path provided as the Name of the database. You will get failures in subsequent attempts because the database is already attached unless you have detached the database somewhere else in your code.
AttachDbFilename is mostly useful when working with User Instances, which you're not using, so I'm unclear why your're using this keyword. Why aren't you just attaching your database once and then connecting to it normally?
Mike
No comments:
Post a Comment