Solved

Timeout MSSqlServer 2005 from VB6 during Open Table

Posted on 2008-06-13
8
505 Views
Last Modified: 2011-09-20
Hallo Experts,
My Vb6 Application tries to open a Table to add new records to this table.
Mostly during system backup time i get this message:
"Abfragetimeout abgelaufen (-2147217871)" (meaning something like "retrieval timeou") after 30 s.
I did not found a means to change this timeout (oconn.CommandTimeout = 120 did not work)
Any suggestion?
Josef
Dim oConn As ADODB.Connection

  Dim rst1 As ADODB.Recordset
 

  Set oConn = New ADODB.Connection

  With oConn

    .Provider = sProvider

    .Properties("Data Source") = sDataSource

    .Properties("User ID") = sUserID

    .Properties("Password") = sPassword

    .Properties("Initial Catalog") = sInitialCatalog

    .CursorLocation = adUseClient

'    .ConnectionTimeout = 120 'no difference

'    .CommandTimeout = 120    'no difference

    .Open

  End With 'oConn
 

  Set rst1 = New ADODB.Recordset

  rst1.CursorType = adOpenKeyset

  rst1.LockType = adLockBatchOptimistic
 

  rst1.Open "Messwerte", oConn.ConnectionString, , , adCmdTable
 

'here the timeout occurs

Open in new window

0
Comment
Question by:joschramm
  • 4
  • 4
8 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21777271
change:
  rst1.Open "Messwerte", oConn.ConnectionString, , , adCmdTable

into:
  rst1.Open "select * from Messwerte where 1=0 ", oConn.ConnectionString

this will return 0 records, be very fast, and still allow you to add new records.

0
 

Author Comment

by:joschramm
ID: 21778257
Many thanks, Angelllll.
i tested your solution  "at home" - seems to work fine (but   h e r e  i get no timeouts at all, of course). Now i sent the application "into the field" and tomorrow i will know more.

You will hear from me,
hpefully josef
0
 

Author Closing Comment

by:joschramm
ID: 31466874
responsetime is down from 15 s to 2 s (mean time during duty hours) respectively from far more then 30 s to 10 s (during backup time). But what magic is here at work? Due to the textbook you have to open the table then add a record.
How comes that your solution "still allow you to add new records"?
sincerly,
Josef
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21784660
<Grading Comments>
responsetime is down from 15 s to 2 s (mean time during duty hours) respectively from far more then 30 s to 10 s (during backup time).
But what magic is here at work? Due to the textbook you have to open the table then add a record.
How comes that your solution "still allow you to add new records"?
sincerly,
Josef
</Grading Comments>

as explained, using the select to return 0 records will avoid that the opentable will have to return ALL (yes, all) the records from the table to the client computer.
so, imagine for a table with 1 Million records, and 10 clients try to add 1 record with the original code :)

this side effect is what the text books do not explain, as it would go much too far in details for just getting the kick off how to work in general... (and maybe to give the experts the way to look good, afterwards :) )

glad it worked for you.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21784667
ps:
>"Abfragetimeout abgelaufen (-2147217871)" (meaning something like "retrieval timeou") after 30 s.
means command timeout has expired...

indeed, the command timeout is at default 30 seconds. you could change the command timeout from 30 to another value (ie 0 for infinite timeout), but as you might want to agree: better make the query short than the wait time long :)
0
 

Author Comment

by:joschramm
ID: 21785117
> you could change the command timeout from 30 to another value (ie 0 for infinite timeout)
but how? (If it will be necessary in other circumstances...)

nevertheless:
> but as you might want to agree: better make the query short than the wait time long :)
I do agree indeed, severe.
Thanks again for your help
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21785194
re: command timeout:

the main problem why the "command timeout" did not work in your original code was this line:
  rst1.Open "Messwerte", oConn.ConnectionString, , , adCmdTable

you passed the connection string instead of the connection object.
  rst1.Open "Messwerte", oConn, , , adCmdTable

that differences solves:
* the connection was already open, so your original code reopened it again with the recordset
* the commandtimeout set on the connection object was not incorporated in the connectionstring returned, hence "ignored"

another way to do it is using the Command Object:
  Dim oConn As ADODB.Connection

  dim oCmd as ADODB.Command

  Dim rst1 As ADODB.Recordset

 

  Set oConn = New ADODB.Connection

  With oConn

    .Provider = sProvider

    .Properties("Data Source") = sDataSource

    .Properties("User ID") = sUserID

    .Properties("Password") = sPassword

    .Properties("Initial Catalog") = sInitialCatalog

    .CursorLocation = adUseClient

'    .ConnectionTimeout = 120 'no difference

'    .CommandTimeout = 120    'no difference

    .Open

  End With 'oConn
 

  Dim oCmd as ADODB.Command

  Set oCmd = New ADODB.Command

  Set oCmd.ActiveConnection = oConn

  oCmd.CommandTimeout = 120

  oCmd.CommandText = "select * from Messwerte where 1=0 "
 

  Set rst1 = New ADODB.Recordset

  rst1.CursorType = adOpenKeyset

  rst1.LockType = adLockBatchOptimistic

 

  rst1.Open oCmd

 

Open in new window

0
 

Author Comment

by:joschramm
ID: 21785379
ah, now I understand it!
very good
Josef
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 56
Order by but want it in specific order 2 26
maro to copy and paste from one worksheet to another based on a condition 11 48
MsgBox 4 48
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.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

895 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

18 Experts available now in Live!

Get 1:1 Help Now