Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"An attempt to attach an auto-named database for file .... A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

I have the correct code for my path i think:

SqlConnection myCon = new SqlConnection(@"Data Source = ASUSPC\SQLEXPRESS; AttachDbFilename = C:\Users\ASUS\Desktop\...\...\...\...\zoo.mdf; Integrated Security = True; Connect Timeout = 30");

What I have tried:

i tried to follow this guy, but didn't work for me
https://www.youtube.com/watch?v=sjWXB0EYmF8 (An attempt to attach an auto-named database for file mdf failed | Solved 100%)

Also i tried to move the file into debug folder and then use that location, but it didn't work for me.
Posted
Updated 6-Mar-23 2:32am
v2
Comments
Richard MacCutchan 6-Mar-23 8:02am    
Please show the actual path used in the connection string, and the actual location of the file.
PetkoPet 6-Mar-23 8:07am    
SqlConnection myCon = new SqlConnection(@"Data Source = ASUSPC\SQLEXPRESS; AttachDbFilename = C:\Users\ASUS\Desktop\Materials\Prakt\Project\Zoo\zoo.mdf; Integrated Security = True; Connect Timeout = 30");
Richard Deeming 6-Mar-23 8:33am    
I've removed the link to the YouTube video, since it could make your question look like spam. Since you said it didn't work, we don't want to give that video any extra traffic! :)

Try changing your connection string to:
SqlConnection myCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;Database=someNameYouComeUpWith;AttachDbFilename=...
 
Share this answer
 
You can't attach a DB on your computer to a server on a different one, or to a file located on a different user account: that's what the error is saying.
Either the file is not on the server - in which case it doesn't have access to it because it's on your machine - or it's inaccessible because SQL Server doesn't run under your user account, it has it's own - and that user has no access to your files!
 
Share this answer
 

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