• conn.connectiontimeout,conn.commandtimeout,command.commandtimeout?


    设置超时时有几个地方需要注意:
    一、Connection的超时,包括Connection.ConnectionTimeout和Connection.CommandTimeout两部分,都必须设好;

    二、Command的超时,需要设Command.CommandTimeout的值。

    如果直接用Connection对象来Execute一个SQL语句,那它的CommandTimeout必须设好;
    如果用一个Command对象来执行SQL语句,那Command对象的Commandtimeout必须设好;
    当然,无论哪种情况,Connection对象的ConnectionTimeout是必须要设的。
    ConnectionTimeOut As Integer 默认 15秒
    例子:

    ' DSNLess Connection using the OLE DB provider for ODBC - MSDASQL
    Public Function ConnectSQLServer(ByVal ServerName As String, ByVal DBName As String, ByVal UserName As String, ByVal PWD As String, Optional ByVal ConnectionTimeOut As Integer = 15) As Boolean
        Dim strConnect As String
       
        On Error GoTo Error_ConnectSQLServer
        ' DSNLess Connection using the OLE DB provider for ODBC - MSDASQL
        cn.CursorLocation = adUseClient
        strConnect = "Driver={SQL Server};Server=" & ServerName & ";DataBase=" & DBName & ";UID=" & UserName & ";PWD=" & PWD & ";"
        cn.ConnectionTimeOut = ConnectionTimeOut
        cn.Open strConnect
           
        ConnectSQLServer = True
        Exit Function
       
    Error_ConnectSQLServer:
        ConnectSQLServer = False
    End Function

    ConnectionTimeout 属性
         

    指示在终止尝试和产生错误前建立连接期间所等待的时间。

    设置和返回值

    设置或返回指示等待连接打开的时间的长整型值(单位为秒)。默认值为 15。

    说明

    如果由于网络拥塞或服务器负载过重导致的延迟使得必须放弃连接尝试时,请使用 Connection 对象的 ConnectionTimeout 属性。如果打开连接前所经过的时间超过 ConnectionTimeout 属性上设置的时间,将产生错误,并且 ADO 将取消该尝试。如果将该属性设置为零,ADO 将无限等待直到连接打开。请确认正在对其编写代码的提供者会支持 ConnectionTimeout 功能。

    连接关闭时 ConnectionTimeout 属性为读/写,而打开时其属性为只读。

    CommandTimeout 属性
         

    指示在终止尝试和产生错误之前执行命令期间需等待的时间。

    设置和返回值

    设置或返回长整型值,该值指示等待命令执行的时间(单位为秒)。默认值为 30。

    说明

    使用 Connection 对象或 Command 上的 CommandTimeout 属性,允许由于网络拥塞或服务器负载过重产生的延迟而取消 Execute 方法调用。如果在 CommandTimeout 属性中设置的时间间隔内没有完成命令执行,将产生错误,然后 ADO 将取消该命令。如果将该属性设置为零,ADO 将无限期等待直到命令执行完毕。请确保正在写入代码的提供者和数据源支持 CommandTimeout 功能。

    Connection 对象的 CommandTimeout 设置不会对相同 Connection 上 Command 对象的 CommandTimeout 设置产生影响,即 Command 对象的 CommandTimeout 属性不继承 Connection 对象的 CommandTimeout 的值。

    在 Connection 对象上,打开 Connection 后,CommandTimeout 属性将保持读/写。

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    html5 canvas ( 画一个五角星 ) lineJoin miterLimit
    html5 canvas ( 线段端点的样式 ) lineCap
    html5 canvas ( 矩形的绘制 ) rect, strokeRect, fillRect
    html5 canvas ( 填充图形的绘制 ) closePath, fillStyle, fill
    html5 canvas ( 线段的绘制 ) beginPath, moveTo, strokeStyle, stroke
    c#.net 实现多图上传
    html 浏览器接收的常用 content-type
    node 使用 fs, url, http 模块,组合成小型的服务器 ( 满足html请求, get, post 传值 )
    java servlet 接收上传的文件(commons-fileupload, commons-io)
    java 读取 properties 资源文件
  • 原文地址:https://www.cnblogs.com/Athrun/p/1146368.html
Copyright © 2020-2023  润新知