Click here to Skip to main content
14,603,049 members
Rate this:
Please Sign up or sign in to 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

<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
Rate this:
Please Sign up or sign in to vote.

Solution 1

In you connection string just add the 'database=<database name>'. This prevents SQL server to create the auto-named database.
   
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!
Rate this:
Please Sign up or sign in to vote.

Solution 2

keep the database file in deployment folder.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\Users\Amir\Documents\Visual Studio 2012\Projects\amlak\amlak\Database.mdf";Integrated Security=True;Connect Timeout=30
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100