I'm getting the following error when running my application:
An attempt to attach an auto-named database for file C:\Users\Bryan\Documents\Visual Studio 2015\Projects\app\app.UI\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Here is my connection string:
<connectionStrings>
<add name="SoundyDB" connectionString="data source=BRYAN\SQLEXPRESS;initial catalog=MusicKarma;User id = BRYAN\bryan; password=; MultipleActiveResultSets=True;App=Soundy" providerName="System.Data.SqlClient" />
</connectionStrings>
I want to use SQL-server and my Database MusicKarma.
When I debug my application and inspect the connectionString-variable, It has the following value:
connectionString = "data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
I'm setting the connectionString variable this way:
public UserStore(string connectionString)
{
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentException("Connectionstring");
}
this.connectionString = connectionString;
}
public UserStore()
{
this.connectionString = ConfigurationManager.ConnectionStrings[0].ConnectionString;
}
You need to replace userStore method with the following:
public UserStore()
{
this.connectionString = ConfigurationManager.ConnectionStrings["SoundyDB"].ConnectionString;
}