asp.net Accee数据库连接不稳定解决方案(2)


private static void PrepareCommand(OldbCommand command, OldbConnection connection, OldbTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection) {
if (command == null) throw new ArgumentNullException("command");
if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText");
// If the provided connection is not open, we will open it
if (connection.State != ConnectionState.Open) {
mustCloseConnection = true;
connection.Open();
}
else {
mustCloseConnection = false;
}
// Associate the connection with the command
command.Connection = connection;
// Set the command text (stored procedure name or SQL statement)
command.CommandText = commandText;
//Set the command Time
command.CommandTimeout = 60;
// If we were provided a transaction, assign it
if (transaction != null) {
if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
command.Transaction = transaction;
}
// Set the command type
command.CommandType = commandType;
// Attach the command parameters if they are provided
if (commandParameters != null) {
AttachParameters(command, commandParameters);
}
return;
}


上面是我用的那个类,修改的时间位置。已经用背景标出来了。
呵呵,这个连接不稳定的问题到此就结束了。
本文专业技术是ASP.Net开发,在次谢谢你对我的博客的关注。
有问题也可以加我Q我哦。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjfwwp.html