我有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