+ Reply to Thread
Results 1 to 2 of 2

ADODB Timeout

  1. #1
    MChrist
    Guest

    ADODB Timeout

    I'm trying to use the following ADODB connection string to retrieve a dozen
    records from a MS SQL Server database. Everytime I run the routine, I get a
    Timeout Expired error even though I'm using the ConnectionTimeout = 0 in my
    connection string.

    Any thoughts as to why this is happening?

    TIA

    Mark


    Private Sub Test()

    GetData "11/30/2005"

    End Sub

    Public Sub GetData(ByVal dtEnd As Date)

    Dim Cnxn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim strCnxn As String
    Dim strSQL As String

    ' Open connection
    strCnxn = "Provider=SQLOLEDB;Data Source=MY_SRVR;Initial
    Catalog=MY_DB;User Id=MY_UID;Password=MY_PWD;"
    Set Cnxn = New ADODB.Connection
    Cnxn.CursorLocation = adUseClient
    Cnxn.ConnectionTimeout = 0
    Cnxn.Open strCnxn

    'SQL to call from db
    Set rs = New ADODB.Recordset
    strSQL = "SELECT * FROM dbo.fnMetrics('" _
    & Format(dtEnd, "mm/dd/yyyy") & "')"

    rs.Open strSQL, Cnxn, adOpenStatic, adLockReadOnly, adCmdText

    Range("Metrics_Data").CopyFromRecordset rs

    rs.Close
    Cnxn.Close

    End Sub

  2. #2
    MChrist
    Guest

    RE: ADODB Timeout

    Never mind I figured it out by adding the following command code. Apparently
    the command timeout is the important one, not the connection timeout.

    Set cmd = New ADODB.Command
    cmd.ActiveConnection = Cnxn
    cmd.CommandTimeout = 0
    cmd.CommandText = strSQL
    cmd.CommandType = adCmdText

    Set rs = cmd.Execute




    "MChrist" wrote:

    > I'm trying to use the following ADODB connection string to retrieve a dozen
    > records from a MS SQL Server database. Everytime I run the routine, I get a
    > Timeout Expired error even though I'm using the ConnectionTimeout = 0 in my
    > connection string.
    >
    > Any thoughts as to why this is happening?
    >
    > TIA
    >
    > Mark
    >
    >
    > Private Sub Test()
    >
    > GetData "11/30/2005"
    >
    > End Sub
    >
    > Public Sub GetData(ByVal dtEnd As Date)
    >
    > Dim Cnxn As ADODB.Connection
    > Dim rs As ADODB.Recordset
    > Dim strCnxn As String
    > Dim strSQL As String
    >
    > ' Open connection
    > strCnxn = "Provider=SQLOLEDB;Data Source=MY_SRVR;Initial
    > Catalog=MY_DB;User Id=MY_UID;Password=MY_PWD;"
    > Set Cnxn = New ADODB.Connection
    > Cnxn.CursorLocation = adUseClient
    > Cnxn.ConnectionTimeout = 0
    > Cnxn.Open strCnxn
    >
    > 'SQL to call from db
    > Set rs = New ADODB.Recordset
    > strSQL = "SELECT * FROM dbo.fnMetrics('" _
    > & Format(dtEnd, "mm/dd/yyyy") & "')"
    >
    > rs.Open strSQL, Cnxn, adOpenStatic, adLockReadOnly, adCmdText
    >
    > Range("Metrics_Data").CopyFromRecordset rs
    >
    > rs.Close
    > Cnxn.Close
    >
    > End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1