日期:2014-05-16 浏览次数:20919 次
public bool TestConnection()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=(LocalDB) \v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
try
{
conn.Open();
return (conn.State == ConnectionState.Open);
}
catch (SqlException ex)
{
return false;
}
finally
{
conn.Close();
}
}