我想打开一个.mdf
数据库连接,但是我遇到的问题是,当我用连接字符串打开连接时,我遇到一个错误,该错误提示我该连接未打开。
在这里您可以看到我的代码:
connectionstring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;Connect Timeout=30";
string secure_guid = "";
using (SqlConnection connection = new SqlConnection(connectionstring))
{
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandText = @"SELECT * FROM dbo.Clients
WHERE public_guid = @public_guid";
command.Parameters.AddWithValue("public_guid", Public_Guid.ToString());
secure_guid = Convert.ToString(command.ExecuteScalar());
connection.Close();
}