Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
We have a SQL database file in folder in project and the connection string is :
SQL
public string Access_Con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB\Financial.mdf;Integrated Security=True;User Instance=True;";

and we face following error:

Quote:
An attempt to attach an auto-named database for file failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.


but when change connection string to :

C#
public string Access_Con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|E:\AS-Accounting\Main-proj\accounting\Bisha_accounting\bin\Debug\DB\Financial.mdf ;Integrated Security=True;User Instance=True;";

that's run correctly.

thanks a lot.
Posted
Updated 2-Aug-15 4:34am
v3
Comments
j snooze 17-Jul-15 17:09pm    
if its working correctly what is the issue?
bernova 17-Jul-15 17:18pm    
I have been face above error
[no name] 17-Jul-15 17:45pm    
And? The error message is perfectly clear and specific.
phil.o 18-Jul-15 1:44am    
What is the problem if you have a working way? What is the question?

1 solution

Are you CRAZY? why did you put your database into the BIN folder??? what's wrong with you, man? The correct location is following: E:\AS-Accounting\Main-proj\accounting\Bisha_accounting\AppData\DB\Financial.mdf

if you move your DB in there your connection string would work.
The |DataDirectory| directive is mapped to the AppData application folder. Bisha, please, don't do stupid things, keep professional!
 
Share this answer
 
Comments
bernova 25-Jul-15 5:38am    
please keep calm. I just ask a question!!!!!!!.
I thinks you are very very professional. but the professional man should use Polite words
my problem is solved.
I change the connection string to :
DataSource=.;Initial Catalog=Finanacial.mdf;Integrated Security=true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900