Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO - SQL Server ConnectionTimeout

Posted on 2001-06-03
4
Medium Priority
?
196 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 600 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 70

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

972 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