xAminex
xAminex

Reputation: 483

A database > with the same name exists (Visual studio 2015, Vb.net, local DB)

my connection string is:

con.ConnectionString = " Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=|DataDirectory|\ Database1.mdf;Integrated Security=true;"

my app.config is :

<connectionStrings>
        <add name="materials_summury.My.MySettings.Database1ConnectionString"
            connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>

but I got the error message :

An attempt to attach an auto-named database for file C:\Users\example\Documents\Visual Studio 2015\Projects\materials summury\materials summury\bin\Debug\ Database1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

can you please help ? I'm under VS 2015 express it's a localdb. Thanks in advance

Upvotes: 0

Views: 2453

Answers (1)

Ken White
Ken White

Reputation: 125748

You have what looks to be an embedded space in your connection string between \ and Database1.mdf:

AttachDbFilename=|DataDirectory|\ Database1.mdf
                                 |
                                 |
                                 Note the space

Unless your database is really named " Database1.mdf", I'd suspect that it's causing the issue you're experiencing.

Upvotes: 1

Related Questions