简体   繁体   English

从 MS Access 在 SQL Server 中使用截断

[英]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) SQL Server 2008 中的 Sproc 调用:TRUNCATE TABLE tablename(30,000 条记录)
  2. MS Access (2010) Client MS Access (2010) 客户端
  3. A Batch file that uses SQLCMD Utility to call the Stored Procedure使用 SQLCMD 实用程序调用存储过程的批处理文件

Within my Access client, I am using vba/Shell() method to call the Batch file.在我的 Access 客户端中,我使用 vba/Shell() 方法来调用批处理文件。 The batch file then uses SQLCMD to connect to SQL Server and call the SPROC.然后批处理文件使用 SQLCMD 连接到 SQL Server 并调用 SPROC。

If I click on the batch file directly from my machine, it works perfect, 2 seconds max.如果我直接从我的机器上单击批处理文件,它可以完美运行,最多 2 秒。 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.如果我使用 Shell() 方法从 Access 中运行批处理文件,它似乎将 SPROC 中的 TRUNCATE 视为 DELETE 而不是 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.如果我在只有几千条记录的表上做同样的事情,它会成功,大约 5 秒。

I know, "don't use Access as a client"!我知道,“不要将 Access 用作客户端”! I inherited this app from Non-IT so I have to make it work, no funds to re-architect it.我从非 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?您是否尝试在调用 sproc 的 SQL Server 代理中设置按需作业? You can then just run the job with a t-sql command.然后,您可以使用 t-sql 命令运行该作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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