ODBC 调用失败,存储过程 - 通过查询

ODBC Call Failed with stored procedure - Pass through query(ODBC 调用失败,存储过程 - 通过查询)
本文介绍了ODBC 调用失败,存储过程 - 通过查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个传递查询并尝试从中调用存储过程.

I have created a pass through query and trying to call a stored procedure from it.

我能够成功地在 sql server 数据库上执行查询,但是当涉及到存储过程时,我收到一个错误:

I am able to execute the queries on sql server database sucessfully but when it comes to stored procedures, i am getting an error as :

"ODBC 调用失败"

问题仅在于存储过程.查询执行良好.

The problem is with stored procedures only. The queries are executing fine .

这是我的代码:

Dim qdf As DAO.QueryDef, rst As ADODB.Recordset
Dim DatabaseName As String
Dim Server As String
ServerName = "XXXX"
DatabaseName = "XXX"
Set qdf = CurrentDb.CreateQueryDef("")
 strConnectionString = "ODBC;DRIVER={sql server};" & _
        "DATABASE=" & DatabaseName & ";" & _
        "SERVER=" & ServerName & ";" & _
        "Trusted_Connection=YES;"
qdf.Connect = strConnectionString
qdf.SQL = " EXEC [dbo].[SAMPLE_TEST]"
qdf.ReturnsRecords = True
Set rst = qdf.OpenRecordset
Debug.Print rst!RecordCount
rst.Close
Set rst = Nothing

如果我遗漏了什么,请告诉我?

推荐答案

获取有关ODBC--调用失败"原因的更多信息.error 我们可以遍历 DBEngine.Errors 集合,看看是否还有其他可能更具描述性的消息.例如,用代码

To get more information about the cause of an "ODBC--call failed." error we can loop through the DBEngine.Errors collection and see if there are other messages that might be a bit more descriptive. For example, with the code

    qdf.Connect = strConnectionString
    qdf.SQL = " EXEC [dbo].[SAMPLE_TEST]"
    qdf.ReturnsRecords = True
    On Error GoTo oops
    Set rst = qdf.OpenRecordset
    Debug.Print rst!RecordCount
    rst.Close
    Set rst = Nothing
    Exit Sub
oops:
    Dim dbeError As Error
    For Each dbeError In DBEngine.Errors
        Debug.Print "(" & dbeError.Number & "): " & dbeError.Description
    Next
End Sub

我们可能会在 VBA 立即窗口中看到以下内容:

we might see the following in the VBA Immediate window:

(229): [Microsoft][ODBC SQL Server Driver][SQL Server]The EXECUTE permission was denied on the object 'SAMPLE_TEST', database 'myDb', schema 'dbo'.
(3146): ODBC--call failed.

当然

对象SAMPLE_TEST"、数据库myDb"、架构dbo"的 EXECUTE 权限被拒绝.

The EXECUTE permission was denied on the object 'SAMPLE_TEST', database 'myDb', schema 'dbo'.

比仅仅有用得多

ODBC--调用失败.

ODBC--call failed.

这篇关于ODBC 调用失败,存储过程 - 通过查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)