Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am a beginer for ms sql server. Please help me to solve this problem.
My connection string is:
@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbInventory.mdf;Integrated Security=True;User Instance=True"

but error occur while opening connection
[System.Data.SqlClient.SqlException] = { "An attempt to attach an auto-named database for file C:\\Inventory\\bin\\Debug\\dbInventory.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share." }
Posted
Updated 10-Feb-10 6:22am
v2

1 solution

It's not a UNC path, and the file will probably exist, leaving one option to verify;

Open SQL Management Studio and check whether there's a database in there with the name. SQL Server can't have two databases that share the same name.

Some background information;

You can "register" a database-file (*.mdf) in SQL Server, that usually referred to as "attaching" the database. The file is then addressed over an alias. This way SQL Server knows where the files are.

You can also connect to a database-file directly, without explicitly attaching it. That's what the part "AttachDbFilename[^]" does.
 
Share this answer
 
v2

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