Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I have created a windows application using LINQ to SQL. After successfully deploying the application i'm getting the error as "An attempt to attach an auto-named database for file <File Name> failed". We have the connection string in app.config file as follows

MSIL
<add name="localserver" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=filepath\bin\Debug\MyDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
     providerName="System.Data.SqlClient" />



How to remove this error?
Posted
Updated 9-Jul-20 21:01pm
v2

In you connection string just add the 'database=<database name>'. This prevents SQL server to create the auto-named database.
 
Share this answer
 
Comments
Member 7797800 6-May-11 2:09am    
can you please explain where exactly do i need to apply this
MarkBennion 1-Aug-15 21:45pm    
Ramalinga, Thank you very much! This started appearing when I went from SQLEXPRESS to MSSQLSERVER. Your solution solved it for me!
keep the database file in deployment folder.
 
Share this answer
 
Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\Users\Amir\Documents\Visual Studio 2012\Projects\amlak\amlak\Database.mdf";Integrated Security=True;Connect Timeout=30
 
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