473,385 Members | 1,813 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,385 software developers and data experts.

Access2003 - sql server 2005, db.execute times out updating sqlserver data

This is the vba code

Set db = CurrentDb
On error goto fErr
…. loop
strSql = "UPDATE tblInvAnalysisWhse" & _
" SET ltDeviation = " & Sqr(dblError /
intPeriods) & _
" WHERE item = '" & Trim(strItem) & "'" & _
" AND location = " & intLocation
dblCount = dblCount + 1
db.Execute strSql, dbFailOnError

fErr:
stop
resume next

db.execute always fails after 1246 iterations, with
- [Microsoft][ODBC SQL Server Driver]Timeout
expired ,ODBC.Database ,0
- ODBC--update on a linked table 'tblInvAnalysisWhse'
failed. ,DAO.Database ,3157
'tblInvAnalysisWhse’ has 107,000+ records, and is a linked sql server
table
Columns item & location are indexed

Strsql on failure is
UPDATE tblInvAnalysisWhse
SET ltDeviation = 9
WHERE item = 'P103 L25348' AND location = 21

If I try to execute the UPDATE statement in sql server, it never
completes (8 mins and running)
There’s nothing in the sql server logs
And my process only has 20 object locks
Until I 'stop' running the ms-access function, and then the sql server
statement completes immediately
Of course, all the locks are gone

so the problem has to do with locks

So what do I need to do, in a vba loop, to free up my sql server locks
after each update statement ?
create a transaction ?
create a passthrough query to do the update ?


Oct 27 '08 #1
7 3433
This is a limitation with Access and ODBC against a sql server. You
would be way better off using ADO to perform this operation - you get
way more bandwidth and can circumvent the record locking issue more
effectively because ADO does not hold the connection open continuously
like ODBC and you can set a timeout with ADO.

A more ideal solution would be to perform this type of operation with
ADO.Net -- but that is .Net country.

Classic ADO (ADO) was specifically designed for interfacing com based
apps (VB6, Access, Excel) with sql server (and Oracle, DB2).

My recommendation would be to use ADO for this operation. There may be
some tweakage you could do to make the ODBC setup work better - I don't
know it - but it is tweakage. ADO is straight forward - simple. Here
is a sample:

----------------------------------------

'--make a reference to Microsoft ActiveX Data Object 2.5 (or higher)
library

Dim cmd As New ADODB.Command
cmd.ActiveConnection = "Provider=SQLOLEDB; Data
Source=yourServer;Database=YourDB;Trusted_Connecti on=Yes"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandTimeout = 600
cmd.CommandType = adCmdText

Do While Not RS.EOF
cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1 =
'ddd'"
cmd.Execute
Loop

----------------------------------------

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Oct 27 '08 #2
On Oct 27, 4:57*pm, Rich P <rpng...@aol.comwrote:
This is a limitation with Access and ODBC against a sql server. *You
would be way better off using ADO to perform this operation - you get
way more bandwidth and can circumvent the record locking issue more
effectively because ADO does not hold the connection open continuously
like ODBC and you can set a timeout with ADO.

A more ideal solution would be to perform this type of operation with
ADO.Net -- but that is .Net country.

Classic ADO (ADO) was specifically designed for interfacing com based
apps (VB6, Access, Excel) with sql server (and Oracle, DB2). *

My recommendation would be to use ADO for this operation. *There may be
some tweakage you could do to make the ODBC setup work better - I don't
know it - but it is tweakage. *ADO is straight forward - simple. *Here
is a sample:

----------------------------------------

'--make a reference to Microsoft ActiveX Data Object 2.5 (or higher)
library

Dim cmd As New ADODB.Command
cmd.ActiveConnection = "Provider=SQLOLEDB; Data
Source=yourServer;Database=YourDB;Trusted_Connecti on=Yes"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandTimeout = 600
cmd.CommandType = adCmdText

Do While Not RS.EOF
* cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1 =
'ddd'"
* *cmd.Execute
Loop

----------------------------------------

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
ok, I tried the ado method proposed, and I get the same error after
1246 'updates'
I also tried, connecting before each update and disconnecting
afterwards

Dim cmd As ADODB.Command

Do While Not RS.EOF
set cmd = new adodb.command
cmd.ActiveConnection = "Provider=SQLOLEDB; Data
Source=yourServer;Database=YourDB;Trusted_Connecti on=Yes"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandTimeout = 600
cmd.CommandType = adCmdText
cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1
=
'ddd'"
cmd.Execute
set cmd = nothing
Loop

and it still fails after 1269 passes...

what am I missing ?
ps. I tried both encapsulating the updates in a 'transaction' as well
as using a passthrough query... same problem, same number of passes
Oct 28 '08 #3
On Oct 28, 12:58*pm, Roger <lesperan...@natpro.comwrote:
On Oct 27, 4:57*pm, Rich P <rpng...@aol.comwrote:


This is a limitation with Access and ODBC against a sql server. *You
would be way better off using ADO to perform this operation - you get
way more bandwidth and can circumvent the record locking issue more
effectively because ADO does not hold the connection open continuously
like ODBC and you can set a timeout with ADO.
A more ideal solution would be to perform this type of operation with
ADO.Net -- but that is .Net country.
Classic ADO (ADO) was specifically designed for interfacing com based
apps (VB6, Access, Excel) with sql server (and Oracle, DB2). *
My recommendation would be to use ADO for this operation. *There may be
some tweakage you could do to make the ODBC setup work better - I don't
know it - but it is tweakage. *ADO is straight forward - simple. *Here
is a sample:
----------------------------------------
'--make a reference to Microsoft ActiveX Data Object 2.5 (or higher)
library
Dim cmd As New ADODB.Command
cmd.ActiveConnection = "Provider=SQLOLEDB; Data
Source=yourServer;Database=YourDB;Trusted_Connecti on=Yes"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandTimeout = 600
cmd.CommandType = adCmdText
Do While Not RS.EOF
* cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1 =
'ddd'"
* *cmd.Execute
Loop
----------------------------------------
Rich
*** Sent via Developersdexhttp://www.developersdex.com***

ok, I tried the ado method proposed, and I get the same error after
1246 'updates'
I also tried, connecting before each update and disconnecting
afterwards

Dim cmd As ADODB.Command

*Do While Not RS.EOF
* *set cmd = new adodb.command
* *cmd.ActiveConnection = "Provider=SQLOLEDB; Data
* *Source=yourServer;Database=YourDB;Trusted_Connect ion=Yes"
* *cmd.ActiveConnection.CursorLocation = adUseClient
* *cmd.CommandTimeout = 600
* *cmd.CommandType = adCmdText
* *cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1
=
*'ddd'"
* * cmd.Execute
* * set cmd = nothing
*Loop

and it still fails after 1269 passes...

what am I missing ?

ps. *I tried both encapsulating the updates in a 'transaction' as well
as using a passthrough query... same problem, same number of passes- Hidequoted text -

- Show quoted text -
went back to using a passthrough query but changed the function to
populate the passthrough with 500 update statements at a time before
executing it

and it fails with timeout on the third execute (1001 - 1500th
updates)..
so why can't sql server process more than 1269 updates
and why does 'stopping' code execution allow the passthrough to then
execute successfully ?
Oct 29 '08 #4
Hi Roger,

Note: I don't think the problem was with ODBC after all. The problem
may be with the data at a certain point in your procedure.

Try this: go back to the ADO loop (or ODBC - don't think it matters at
this point) - add a loop counter so that you know at what iteration of
the loop you have the problem. I think the problem is with the
parameter(s) you are passing or the row you are trying to update at that
iteration. You want to isolate that row (or params you are passing).
Once you have clearly identified that row or param - use a where clause
to exclude it and see if your procedure runs.

Another thought would be to try running your procedure from a starting
point after the point where you are encountering your problem. If the
procedure runs OK after that point - then there is a problem with the
data - most likely some null/nulling issue where the query is trying to
guess what to do but there is nothing there for it to do anything with
at that point (I will take a guess that maybe at the point whwere the
timeout occurs the problem may be in your where clause - not accounting
for somethign at some row).
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Oct 29 '08 #5
On Oct 29, 9:18*am, Rich P <rpng...@aol.comwrote:
Hi Roger,

Note: *I don't think the problem was with ODBC after all. *The problem
may be with the data at a certain point in your procedure.

Try this: *go back to the ADO loop (or ODBC - don't think it matters at
this point) - add a loop counter so that you know at what iteration of
the loop you have the problem. *I think the problem is with the
parameter(s) you are passing or the row you are trying to update at that
iteration. *You want to isolate that row (or params you are passing).
Once you have clearly identified that row or param - use a where clause
to exclude it and see if your procedure runs. *

Another thought would be to try running your procedure from a starting
point after the point where you are encountering your problem. *If the
procedure runs OK after that point - then there is a problem with the
data - most likely some null/nulling issue where the query is trying to
guess what to do but there is nothing there for it to do anything with
at that point (I will take a guess that maybe at the point whwere the
timeout occurs the problem may be in your where clause - not accounting
for somethign at some row).

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
since I was creating a passthrough query, with 500 update statements
and it failed on the 3rd pass, I copied all 1500 update queries into
one sql server statement

it runs without a problem

since I already had a counter has you suggested, and it indicates that
the failure occurs on the 1269th iteration, and since sql server can
process all 1500 statements, I'm guess the problem is elsewhere

but the same function works fine in access97, accessing the same sql
server 2005 tables....

so I'm going to try an adodb recordset instead of a dao recordset in
this loop
Do While Not RS.EOF
cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1
=
'ddd'"
cmd.Execute
Loop
Oct 29 '08 #6
On Oct 29, 9:44*am, Roger <lesperan...@natpro.comwrote:
On Oct 29, 9:18*am, Rich P <rpng...@aol.comwrote:


Hi Roger,
Note: *I don't think the problem was with ODBC after all. *The problem
may be with the data at a certain point in your procedure.
Try this: *go back to the ADO loop (or ODBC - don't think it matters at
this point) - add a loop counter so that you know at what iteration of
the loop you have the problem. *I think the problem is with the
parameter(s) you are passing or the row you are trying to update at that
iteration. *You want to isolate that row (or params you are passing).
Once you have clearly identified that row or param - use a where clause
to exclude it and see if your procedure runs. *
Another thought would be to try running your procedure from a starting
point after the point where you are encountering your problem. *If the
procedure runs OK after that point - then there is a problem with the
data - most likely some null/nulling issue where the query is trying to
guess what to do but there is nothing there for it to do anything with
at that point (I will take a guess that maybe at the point whwere the
timeout occurs the problem may be in your where clause - not accounting
for somethign at some row).
Rich
*** Sent via Developersdexhttp://www.developersdex.com***

since I was creating a passthrough query, with 500 update statements
and it failed on the 3rd pass, I copied all 1500 update queries into
one sql server statement

it runs without a problem

since I already had a counter has you suggested, and it indicates that
the failure occurs on the 1269th iteration, and since sql server can
process all 1500 statements, I'm guess the problem is elsewhere

but the same function works fine in access97, accessing the same sql
server 2005 tables....

so I'm going to try an adodb recordset instead of a dao recordset in
this loop
Do While Not RS.EOF
* cmd.CommandText = "Update tblz Set fld5 = ' & rs(1) & ' Where fld1
=
'ddd'"
* *cmd.Execute
Loop- Hide quoted text -

- Show quoted text -
changing RS to an ADODB recordset solves the problem, I'm just not
sure why
Oct 29 '08 #7
Not to knock ODBC, but I have consistently had less problems and way
more performance using ADO (ADODB) against the sql server from Access
(and Excel). But if you will be interfacing with sql server on a
consistent basis (like from now forward) I would recommend stepping up
to ADO.Net. ADODB supercedes ODBC, and ADO.Net supercedes ADODB. The
improvements between ADO.Net and ADODB is more substantial than the
improvements between ADODB and ODBC. To Date: nothing commercial can
outperform ADO.Net against any current RDBMS (Sql server, Oracle of the
ones I know of).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Oct 29 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: AlessanBar | last post by:
Hello Friends !! I have a strange problem, and I need to know what would be the source of this. I have a laptop computer with the following configuration: Pentium III Brand : Toshiba Speed :...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
9
by: billmiami2 | last post by:
I was playing around with the new SQL 2005 CLR functionality and remembered this discussion that I had with Erland Sommarskog concerning performance of scalar UDFs some time ago (See "Calling...
10
by: amjad | last post by:
how to connection sql server table with aspx like pulling data from table to grid view.... simple example to start .... thanks
2
by: R.A.M. | last post by:
Hello, I am learning .NET 2.0. I need to write an assembly to be added to SQL Server 2005 database DemoSQLServer, with stored procedures. According to one of my books I wrote (Demo.cs): using...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: thersitz | last post by:
Hi, I have VStudio2005, SQLServer 2005 dev edition loaded on a windowsXP Pro machine. I installed it ok. I just attempted to load the Personal Web Site Starter Kit (I downloaded off...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.