我有ASP.net項目與其中的localDB。 數據庫文件名是ProjectDB.sdf,我將它放在App_Data文件夾中。將LocalDB連接到ASP.net項目
我的連接字符串是:
<add name="ProjectConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ProjectDB.sdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
我嘗試使用該數據庫在我的CS文件是這樣的:
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();
應用落在conn.Open();命令。
該錯誤消息我得到說:
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.
我在做什麼錯?
預先感謝您!
檢查這個線程:嘗試附加自動命名的數據庫(HTTP:/ /stackoverflow.com/questions/12566036/an-attempt-to-attach-an-auto-named-database-for-file-database1-mdf-failed) –
使用SQL Server Express代替 – ErikEJ