c#数据库错误
有谁能告诉我为什么会出现这个错误: 存在同名的数据库,或者无法创建指定的文件 已打开,或位于UNC共享上 假设您已经选中了“指定的文件无法打开,或者位于UNC共享上”&该位置确实存在c#数据库错误,c#,database,sql-server-express,C#,Database,Sql Server Express,有谁能告诉我为什么会出现这个错误: 存在同名的数据库,或者无法创建指定的文件 已打开,或位于UNC共享上 假设您已经选中了“指定的文件无法打开,或者位于UNC共享上”&该位置确实存在.mdf,我认为您不需要在连接字符串中使用引号: SqlConnection con = new SqlConnection(@"Server=.\SQLEXPRESS;AttachDbFilename='C:\HashTags.mdf';Integrated Security=True;User Instance=
.mdf
,我认为您不需要在连接字符串中使用引号:
SqlConnection con = new SqlConnection(@"Server=.\SQLEXPRESS;AttachDbFilename='C:\HashTags.mdf';Integrated Security=True;User Instance=True");
con.Open();
String queryStr = "SELECT name FROM ttable WHERE name LIKE '*%'";
SqlCommand com = new SqlCommand(queryStr, con);
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
this.trendingBx.Text = sdr.GetValue(0).ToString();
}
sdr.Close();
应该是:
AttachDbFilename='C:\HashTags.mdf'
这在我看来应该是可行的。假设您已经选中了“指定的文件无法打开,或者它位于UNC共享上”.mdf
确实存在于该位置,我认为您不需要在连接字符串中加引号:
SqlConnection con = new SqlConnection(@"Server=.\SQLEXPRESS;AttachDbFilename='C:\HashTags.mdf';Integrated Security=True;User Instance=True");
con.Open();
String queryStr = "SELECT name FROM ttable WHERE name LIKE '*%'";
SqlCommand com = new SqlCommand(queryStr, con);
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
this.trendingBx.Text = sdr.GetValue(0).ToString();
}
sdr.Close();
应该是:
AttachDbFilename='C:\HashTags.mdf'
这在我看来应该是可行的。您应该使用:
AttachDbFilename=C:\HashTags.mdf (no single quotes)
Integrated Security=True
不是
Integrated Security=SSPI
在您的连接字符串中。您应该使用:
AttachDbFilename=C:\HashTags.mdf (no single quotes)
Integrated Security=True
不是
Integrated Security=SSPI
在连接字符串中。是否确定数据库尚未连接?如果是,您应该使用:
AttachDbFilename=C:\HashTags.mdf (no single quotes)
Integrated Security=True
您确定数据库尚未连接吗?如果是,您应该使用:
AttachDbFilename=C:\HashTags.mdf (no single quotes)
Integrated Security=True
SqlConnection con=newsqlconnection(@“Server=。\SQLEXPRESS;Database=HashTags;integratedsecurity=sspi”);SqlConnection con=newsqlconnection(@“Server=。\SQLEXPRESS;Database=HashTags;integratedsecurity=sspi”);