views:

49

answers:

4

I am testing the error-handling of an Access-VBA controlled process:

  1. A script in an Access 'controller' DB starts.
  2. The script starts a macro in a 2nd Access file (the 'database').
  3. The macro in the 'database' file runs a bunch of maketable queries.
  4. These queries pull from tables linked to an ODBC source (SQL-Server actually).

When this process runs in the early morning hours, sometimes the queries time out. Today, I've updated the error-handling in the controller script, so I want to simulate a time-out error.

I've looked at the ODBC administrator and Advanced options in MS Access, but I'm not finding what I need. Ideas?

+1  A: 

Open your macro in design view. Under the View menu, select Properties. It should be a Timeout property, set it to a short value and test.

vulkanino
Good idea, but didn't work. I think that property is only used *after* the server fails to respond.
PowerUser
A: 

Within your SQL Queries add the following statement - it should cause a timeout.

--waits for 5 mins
    WaitFor Delay '00:05'

Or if you don't want to amend existing queries you can run this over one of the tables that the macro queries. This will lock the table for 3 mins

begin transaction

Select *
From MyTable with (TABLOCKX)
--wait for 3 min
WaitFor Delay '00:03'

rollback transaction
Barry
I'm using your transaction example in a pass-thru query, but it keeps prompting me for a datasource. How do I put the datasource into the transaction?
PowerUser
@PowerUser - Can you not run this query in a SSMS Query window? To be honest I don't know too much about MS Access.
Barry
Sorry, but I don't even know what a SSMS Query window is. Pretty sure Access doesn't have it.
PowerUser
@Pow – If it's a SQL Server data source, then someone at your company knows how to connect to that database directly and issue commands. One tool for doing this is called SQL Server Management Studio (SSMS). That is the context for the commands that Barry is suggesting to you.
Emtucifor
@Em: thanks for the explanation.
PowerUser
A: 

If your queries are modifications, you can add a trigger which invokes WAITFOR. Described here.

AlexKuznetsov
+1  A: 

re: sometimes the queries time out.

Make sure your query property for ODBC timeout is set to zero so it doesn't generate an error but continues running.

Beth
+1 for a good idea. But if I did that, my reports will back up into one another.
PowerUser
not if they're called sequentially in a macro or in code. are they dependent on each others results?
Beth
If I ran them sequentially and the first report was delayed by an hour, then every report after that would also be delayed. I would rather the first report just give up after a few minutes and move on to the next.
PowerUser
ok, then you can set the query timeout property to 1 and it will timeout when it takes longer than 1 second to return.
Beth
Right now, the scripts are all in separate files called by the windows task scheduler. So, your suggestion makes sense in the long run, but I'd have to reengineer the whole thing.
PowerUser
why would you have to reengineer anything? In one of the queries which normally runs longer than 1 second, change the property value for ODBC timeout to 1.
Beth
oh, yeah, that part I already tried and the query ran normally. I think that property only kicks in if the server doesn't respond.
PowerUser
OK, then, link it to a server that doesn't exist
Beth
That... sounds plausible. I'll have to try it out tomorrow.
PowerUser