Prevent Time out error from happening?

Posted on 2008-10-27
Last Modified: 2011-10-19
I have a stored procedure which takes long to complete, because it does a bulk import on a very large file. If I call this stored procedure I get a time out error, but the procedure is still running correctly.
Is there any way to prevent this?

Question by:Schuttend
  • 2
  • 2
  • 2
  • +1

Expert Comment

ID: 22816705
Do you prove to change the time out of the command/connection object?
If you set the property to zero, ADO will wait indefinitely until the execution is complete.
Make sure the provider and data source to which you are writing code support the CommandTimeout/ConnectionTimeout  functionality.

Ing. Fernando D. Giletta
San Fco. Cba. Argentina.
LVL 10

Expert Comment

ID: 22816719
on your connection you can set the property CommandTimeout.
Can you give a piece of your code?  Or at least some more info on what you are using to make the connection? ADO, something else?

Do you know how long you stored procedure normally should take?  Can it be optimized? (perhaps turning of full logging on the database for the bulk import?, is this on time import?)

Author Comment

ID: 22817571
Please see attached code below. What would be the correct syntax??

Private Sub Command3_Click()
' for connection strings to sql express, see:
'ado.Open "Driver={SQL Server Native Client 10.0};Server=SCHUTTENVISTA\SQLEXPRESS;Database=master;Uid=sa;Pwd=d27021973;"
Dim cn As ADODB.Connection
    Dim rsCheck As ADODB.Recordset
    Dim cmd As ADODB.Command
       Dim rsRecCount As Integer  ' For counting records in a record set
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Driver={SQL Server Native Client 10.0};Server=SCHUTTENVISTA\SQLEXPRESS;Database=Regus1;Uid=sa;Pwd=d27021973;"
    Set cmd = New ADODB.Command
    cmd.ActiveConnection = cn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "importeren5"
'Call Create_DataBase
'Call Create_Table
'Call Create_Table_Trading
'Call Add_Record1
End Sub

Open in new window

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

LVL 75

Accepted Solution

Anthony Perkins earned 250 total points
ID: 22818349
If you have optimized your stored procedure as much as you are capable, than you may have to resort to modifying the default value of 30 seconds for the CommandTimeout property for the Command object.  You ahve a couple of options:
A.  Increase it to a reasonable amount of time or if you like living dangerously
B.  Change it to 0 and be prepared to wait an indefinite amount of time.

As in:

    Set cmd = New ADODB.Command
    cmd.CommandText = "importeren5"
    cmd.CommandTimeout = 120
    cmd.ActiveConnection = cn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "importeren5"

But chaging the CommandTimeout should only be done as a last resort.  Unfortunately without seeing your code, it is impossible to make any further recommendations.

Author Comment

ID: 22819740
I doubt if the code can be optimized. It's a simple bulk import into sql server. It's about 1 GIG of data and this just takes a while ,about 2-4 minutes.
Is there any method to cancel a called procedure while it's running?
ALTER PROCEDURE [dbo].[importeren5] 
    -- Insert statements for procedure here
	drop table CSVtest99
	create Table CSVtest99
	(	Datum  VARCHAR(30),
	Signal VARCHAR(30),
	Equity VARCHAR(30)
	BULK insert csvtest99
	FROM 'c:\structure\test.txt'

Open in new window

LVL 10

Expert Comment

ID: 22824718
I don not know of a method to cancel from the code side.  But the process can be killed on the sql server to cancel.
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22827585
Yes, you can from code, but it is beyond the scope of this question.

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 77
Recommendation vb6 to or others 14 174
backup program with robocopy 6 43
Dinamic report to Crosstab query 9 33
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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