sql-server - Calling stored procedure from MS Access results in error 3146
问题描述
When I call a SQL Server stored procedure from MS Access front-end using the code shown below, it stops running and throws the runtime error "3146".
This stored procedure is working correctly in SQL Server, but when I run from MS Access, it is working at first, but suddenly stops and throws that runtime error "3146".
For more clearance this stored procedure is for inserting records in an empty table when I do from MS Access it should insert 1000 records, but it inserts 970 records and then stops.
My stored procedure had a select query for inserting records, now I have changed this easy select query to a union query, since I have changed this in the design of stored procedure it is working fine in SQL Server
Public Sub Command0_Click()
Dim qdef As DAO.QueryDef
Set qdef = CurrentDb.CreateQueryDef("")
qdef.Connect = CurrentDb.TableDefs("[ASBUILT_LIST]").Connect
qdef.SQL = "EXEC Update_Asbuilt2"
qdef.ReturnsRecords = False ''avoid 3065 error
qdef.Execute
qdef.Close
Set qdef = Nothing
End Sub
解决方案
如果运行了,但没有到最后,那么很可能不是权限问题,而是超时问题
你可以做一个:
debug.print qdef.ODBCTimeout
知道您当前的超时值是多少。
然后只需增加足够的秒数即可完成存储过程:
Public Sub Command0_Click()
Dim qdef As DAO.QueryDef
Set qdef = CurrentDb.CreateQueryDef("")
qdef.Connect = CurrentDb.TableDefs("[ASBUILT_LIST]").Connect
' --------------- Define TimeOut in Seconds ----------------
qdef.ODBCTimeout = 2000
' ----------------------------------------------------------
qdef.SQL = "EXEC Update_Asbuilt2"
qdef.ReturnsRecords = False ''avoid 3065 error
qdef.Execute
qdef.Close
Set qdef = Nothing
End Sub
推荐阅读
- javascript - Angular 2 更改类名更改类名,然后将其删除
- php - 隐藏 docroot 中的 composer vendor 文件夹
- asp.net - 如何在本地IIS建立测试环境来测试ASP.NET MVC网站?
- python - “ImportError:没有名为 django.core.wsgi 的模块”apache 错误
- javascript - JavaScript 动画上下滚动
- google-cloud-platform - 使用代理对 mqtt.googleapis.com (Cloud IOT) 的 VPC 私有 Google API 访问
- git - git子模块上的“无分支”
- sass - 从源映射键创建类名
- r - 使用 lapply 或 for 循环将多个 csv 文件拉入它们自己的 R 数据帧
- powershell - 按周/月中每一天的持续时间汇总任务?(PoSH)