直到在C#中将事物连接起来为止,什么都不做的最佳方法
|
我正在查看正在连接的应用程序之一中连接到数据库的代码,我看到了
if (_dbConnection == null)
_dbConnection = GetConnection();
while (_dbConnection.State == ConnectionState.Connecting)
{
//Do Nothing until things are connected.
}
if (_dbConnection.State != ConnectionState.Open)
_dbConnection.Open();
var command = GetCommand(commandType);
command.Connection = _dbConnection;
return command;
while循环让我担心。在事物连接好之前,还有什么更好的方法吗?
编辑:
连接如下
private static IDbConnection GetConnection()
{
return new SqlConnection(ConfigurationManager.ConnectionStrings[\"CoonectionStringName\"].ConnectionString);
}
没有找到相关结果
已邀请:
4 个回复
细屠截殴些
镀建啼
而不是
您始终可以使用DbConnection类的StateChange事件而不是while循环。 检查一下
超可林
涸坍饺