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();
Could anyone tell me why I get this error:
A database with the same name exists, or specified file cannot be
opened, or it is located on UNC share.
Are you sure the database is not already attached? If it is you should use: