简体   繁体   中英

Using Truncate in SQL Server from MS Access

I've spent several days on this issue, major research and lot's of trial and error attempts to find a solution. Here is what I have and what I need to make work:

  1. Sproc in SQL Server 2008 that calls: TRUNCATE TABLE tablename (30,000 records)
  2. MS Access (2010) Client
  3. A Batch file that uses SQLCMD Utility to call the Stored Procedure

Within my Access client, I am using vba/Shell() method to call the Batch file. The batch file then uses SQLCMD to connect to SQL Server and call the SPROC.

If I click on the batch file directly from my machine, it works perfect, 2 seconds max. If I run the batch file from within Access using Shell() method, it seems to be treating the TRUNCATE in my SPROC as a DELETE instead of TRUNCATE. It sits idle for several minutes and times out, no records get deleted.

If I do the same on a table with only a few thousand records it succeeds, about 5 seconds.

I know, "don't use Access as a client"! I inherited this app from Non-IT so I have to make it work, no funds to re-architect it.

I have not posted here in ages, so hope I'm fowllowing protocol,

Thanks for any potential solutions in advance,

Have you tried setting up an on demand job in the SQL Server Agent that calls the sproc? You can then just run the job with a t-sql command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM