473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL pass thru VBA / ODBC timeout

I have the following count taking place in my Access VBA code. Sometimes it works, and sometimes it doesnt. Seems the timeout is at 60 and I cant figure out how to change it to 600.

If it errors I'm getting a 3146 ODBC - call failed error

Expand|Select|Wrap|Line Numbers
  1. Public Function GetQueryCount7C() As Long
  2. CurrentDb.QueryTimeout = 0
  3.     Dim rst As DAO.Recordset
  4.     Dim sql As String
  5.  
  6.     sql = "SELECT     COUNT(*)/ 2500 + 1 AS total " _
  7.         & "FROM         Boyd0315Final INNER JOIN " _
  8.         & "InventorySuppliers ON Boyd0315Final.EAN = InventorySuppliers.LocalSKU " _
  9.         & "WHERE     (InventorySuppliers.SupplierID = 315) AND (Boyd0315Final.Cost is not null) AND (InventorySuppliers.Cost <> Boyd0315Final.Cost) OR " _
  10.         & "(InventorySuppliers.SupplierID = 315) and (Boyd0315Final.QOH IS NOT NULL) AND (InventorySuppliers.BoydQuantityAvailable <> Boyd0315Final.QOH)"
  11.         Set rst = CurrentDb.OpenRecordset(sql)
  12.     With rst
  13.  
  14.         If Not .EOF Then
  15.             GetQueryCount7C = .Fields(0).Value
  16.         End If
  17.         .Close
  18.     End With
  19.  
  20.     Set rst = Nothing
  21. End Function
Nov 18 '14 #1
8 2997
jforbes
1,107 Expert 1GB
I think it's because you are setting the timeout on CurrentDB. CurrentDB is a pointer to the currently opened Access database with the twist that the pointer is created each time that your code references it. I'm paraphrasing here, but you get some strange happenings while trying use it and this could be one of those.

It might work if you were to set you database into a variable, try changing:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetQueryCount7C() As Long
  2. CurrentDb.QueryTimeout = 0
  3. Dim rst As DAO.Recordset
  4. Dim sql As String
  5.  
to:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetQueryCount7C() As Long
  2. Dim oDB As DAO.Database
  3. Dim rst As DAO.Recordset
  4. Dim sql As String
  5. Set oDB = CurrentDb()
  6. oDB.QueryTimeout = 120 
An unrelated problem you may run into is that you are mixing and matching ANDs and ORs in your Where clause. This may give you unexpected results.
Nov 18 '14 #2
Thanks for the response. Still receiving the following
Error 3146 ODBC - call failed.

I dont know what you mean by AND's and OR's

I wrote that part in SQL and then copied it and modified it for VBA
Nov 18 '14 #3
Seth Schrock
2,965 Expert 2GB
Between lines 10 and 11, put in the following code:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print sql
This will "print" a line in the immediate window (Ctrl + g will show it if it isn't visible already) then run your code. Please post back what is entered into the immediate window. This will help us make sure that the string is being pieced together correctly.
Nov 18 '14 #4
I'm getting a "2" in the Immediate window..
Nov 19 '14 #5
Seth Schrock
2,965 Expert 2GB
Hmmm. You should be seeing "SELECT COUNT..." Please post your code as you have it now.
Nov 19 '14 #6
Currently have the following. Its timing out doing the select count. If I copy/paste the code into SQL it works fine, but it takes time. The tables are huge.. Hundred million + records..

Expand|Select|Wrap|Line Numbers
  1. Public Function GetQueryCount7C() As Long
  2. CurrentDb.QueryTimeout = 0
  3.     Dim rst As DAO.Recordset
  4.     Dim sql As String
  5.     sql = "SELECT     COUNT(*) / 2500 + 1 AS total " _
  6.         & "FROM         Boyd0315Final INNER JOIN " _
  7.         & "InventorySuppliers ON Boyd0315Final.EAN = InventorySuppliers.LocalSKU " _
  8.         & "WHERE     (InventorySuppliers.SupplierID = 315) AND (Boyd0315Final.Cost is not null) AND (InventorySuppliers.Cost <> Boyd0315Final.Cost) OR " _
  9.         & "(InventorySuppliers.SupplierID = 315) and (Boyd0315Final.QOH IS NOT NULL) AND (InventorySuppliers.BoydQuantityAvailable <> Boyd0315Final.QOH)"
  10.         Set rst = CurrentDb.OpenRecordset(sql)
  11.         Debug.Print sql
  12.     With rst
  13.  
  14.         If Not .EOF Then
  15.             GetQueryCount7C = .Fields(0).Value
  16.         End If
  17.         .Close
  18.     End With
  19.  
  20.     Set rst = Nothing
  21. End Function
Nov 20 '14 #7
I changed the regedit and its running again.. not my ideal solution though..
Nov 20 '14 #8
jforbes
1,107 Expert 1GB
These might not be an option for you, but if you are having this much latency and you are connecting to a SQL Backend that you have access to, there are a couple things you can do to try to speed it up.

You can paste you SQL into Management Studio and then see what the execution plan will be. This would allow you to tweak the query to try to get it to run faster. You might find a simple fix.

Another option is to create a Scalar Function on the SQL Server to return the value you need. What you are doing it a really good fit for a Scalar Function. http://msdn.microsoft.com/en-us/library/ms191320.aspx
Nov 20 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
0
by: Mike Knight | last post by:
I have the following code in an Excel 2003 module that creates a query in MS Access 2003. The created query can then be opened from Access. In Access, right-mouse clicking in design mode, in...
2
by: vulcaned | last post by:
I'm thinking I might want to move the back-end to one of my Access97 applications to SQLServer instead of continuing to use Access jet but before I start/do that I have several questions I'm hoping...
11
by: DFS | last post by:
Architecture: Access 2003 client, Oracle 9i repository, no Access security in place, ODBC linked tables. 100 or so users, in 3 or 4 groups (Oracle roles actually): Admins, Updaters and ReadOnly....
3
by: sloan | last post by:
How does one "pass thru" a Raised Event.... I am using the Adapter Pattern to sync up some different interfaces. http://www.dofactory.com/Patterns/PatternAdapter.aspx My Question is this:
1
by: George | last post by:
Access 2002 SQL Server 2000 ODBC Linked Tables I have a user who gets an ODBC timeout message when trying to save a new record in a form. I looked at the locks on the server and that user was...
1
by: olle | last post by:
Hi. I have the problem that some records in a ms sqlserver table is unable to update from Access. I get the error message odbc-time out error in linked table...... I tried to copy this table...
2
by: teddysnips | last post by:
One of our clients has reported a problem. Everything was working fine on Monday, but since Tuesday all is going wrong. The sysadmin assures me that there have been no changes to the network, or...
15
MMcCarthy
by: MMcCarthy | last post by:
Hi everyone, I have to advise a new client regarding backending some access databases for security reasons. As the issue is one of security I'm assuming they won't want to just link the tables...
10
by: Steve Eslinger | last post by:
I have a query that I built using VB. It takes parameters that I pass in from a form and inserts records into a table. The problem I have is some of the values I enter cause the query to timeout. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.