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

      错误原因点击这

      在上面的几篇中写到连接数据库,出现不稳定是连接池的默认时间改长些,改了之后,要是在很卡的时间内,不停的刷新,可是,就出来了有一个严重的问题是,平凡的数据丢失问题来了,结果我用测试软件来测试,没看到结果,因为我们本地妹有办法测试出来,我的配置和服务器的配置是有点不同的,在说了,通常以个服务器不是和我们的本地那样,就我们一个网站在用,我的类是把SQLHelper连接数据Sql数据库的连接方式改成了连接Access数据库的,类就排除了问题,我只是直接掉用他的类,给了些参数而以,所以这些全是没什么问题的,可以是在很卡的时间内就会出现,去望是找便了,就是没看到结果,我就在后来在英文的博客中看到,原来我勿略了一个属性,这个属性是:OldbConnection成员下的ConnectionTimeout这个连接错误并发时间在什么时间内结束,如果你是在很卡的情况下,正好就是被默认的30秒个定义成看超时状态,你修下里面的如何文件就会恢复正常。结果我个这个属性给了个1分钟,就正常了。我建议你们别给得太长的时间了,给长时间了,一但真的出错了,那可是要把别人的电脑卡定屏幕的哦。总是在那尝试这连接。那经后就会越来越少的人来访问了。

    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我哦。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值