可能重复:
How to check if connection string is valid?有没有标准的.NET方法来测试SqlConnection字符串是否工作?
目前我正在做这样的:
internal bool CheckConnection()
{
using (SqlConnection testConn = new SqlConnection(this.ConnectionString))
{
try
{
testConn.Open();
}
catch (SqlException)
{
return false;
}
}
return true;
}
有没有更好的方式来做到这一点?
这是重复的。如果可能,会删除。 – Crisfole 2010-12-02 19:00:50