I have as ASP.net project with localDB in it. The database file name is ProjectDB.sdf and I placed him in the App_Data folder.
My connection string is:
<add name="ProjectConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ProjectDB.sdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
I try to use the database in my cs file like this:
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ProjectConnection"].ConnectionString;
using(SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select JobTitleId, JobTitleText from LuJobTitle where JobTitleText like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefix);
cmd.Connection = conn;
conn.Open();
The application falls in the conn.Open(); command.
The error message I get says:
An attempt to attach an auto-named database for file d:\user\documents\visual studio 2012\Projects\RealMatchSite\RealMatchSite\App_Data\ProjectDB.sdf failed.
A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
What am I doing wrong?
Thank you in advance!