Solved

ADO - SQL Server ConnectionTimeout

Posted on 2001-06-03
4
187 Views
Last Modified: 2013-11-23
I have successfully connected to my SQL Server db and now can run simple stored procedures and in-line SQL.

However, when I use the code below, which works for other Stored Procedures, to run a Stored Procedure to delete all the rows in a large table I receive a 'Timeout' error.
Checking ADO help I find that I can set a ConnectionTimeout parameter. I have tried this with no success.

Any ideas? ... heres my code...Thanks in anticipation

'##################
Private Sub Command4_Click()
'''''''''''''''''
'My example using ADO to execute a Stored Procedure
'''''''''''''''''

Dim ADOcnn1 As ADODB.Connection
Dim ADOCmd As New ADODB.Command
Dim objErr As ADODB.Error

On Error GoTo Myerr
   
'Open a connection using a DSN and ODBC tags.
Set ADOcnn1 = New ADODB.Connection
ADOcnn1.ConnectionString = "DSN=SQL123;UID=me;PWD=qwert;"
ADOcnn1.ConnectionTimeout = 180
ADOcnn1.Open

'Check the state of the connection to ensure we are connected
If ADOcnn1.State = adStateOpen Then

    'Set the Command object properties
    Set ADOCmd.ActiveConnection = ADOcnn1
    ADOCmd.CommandText = "uSP_Delete_Bang"
    ADOCmd.CommandType = adCmdStoredProc
   
    'Execute the Command object
    ADOCmd.Execute
   
    MsgBox "Complete"
     
    Set ADOCmd = Nothing
    ADOcnn1.Close
    Set ADOcnn1 = Nothing

Else
     
    'Display all errors
    For Each objErr In ADOcnn1.Errors
    Debug.Print objErr.Description
    Next
     
End If


Exit Sub

Myerr:

MsgBox Error + " " + Str(Err)

Exit Sub


End Sub
0
Comment
Question by:jonesgj
4 Comments
 
LVL 15

Accepted Solution

by:
robbert earned 150 total points
ID: 6150126
> Checking ADO help I find that I can set a ConnectionTimeout parameter. I have tried this with no success.

Specify ADOCmd.CommandTimeout, too.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 6150272
You can set the CommandTimeout of the Connection object:
ADOcnn1.CommandTimeout = 300
0
 

Author Comment

by:jonesgj
ID: 6150726
Thanks ....just what I needed..
0
 
LVL 1

Expert Comment

by:jdunck
ID: 6150739
Further, if you are doing a very long execution, and you do not specifically need to wait until the task is done, you can do the following:

objCmd.Execute , adAsyncExecute , adCmdStoredProc+ adExecuteNoRecords

adAsyncExecute indicates that the method should return before finishing the task.

adExecuteNoRecords indicates that the stored proc will not return either a recordset or output params.  Make sure this is the case before you use it... otherwise I'm not sure what will happend.

Both of these should make the call very quick.

Just how large -is- that table, anyway?

If it is very large and heavily indexed, you may need to resort to partitioning...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now