An Attempt to attach an auto-named database Error

Try setting the User Instance property in your connection string to true. You need to add this to your connection string:

User Instance=True

Also just to be sure check again your database server as it might already contain a database with the same name.

Hope that helps.

Change both the current working directory and the connection string to the correct ones to solve it.

Select the database which is located in “Server explorer”
then copy the connection string as exactly seeing in its properties, then use it in the codes.

enter image description here

then for the current working directory use the same path without the database’s name. Solution -> properties -> debug is where the current working directory path is located at. This works for visual studio 2015.

I use my connection string as this

Private constr As String = "Data Source = (LocalDB)MSSQLLocalDB;AttachDbFilename=" +
        Directory.GetCurrentDirectory() + "DBNAME.mdf;" +
        "Integrated Security=True;Connect Timeout=30;User Instance=False"

Leave a Comment