" exec xp_msver 'ProductVersion' " leads to error 2809, if executed via ODBC Connection

Gregorczyk, Tomasz 0 Reputation points
2024-08-12T11:58:23.0933333+00:00

conclusion:

I try the statement exec xp_msver 'ProductVersion' via ODBC in combination with the driver "Sql Server". If I try this, I get the error message " Error requesting "xp_msver" (procedure) because "xp_msver" is a procedure object. ". The statement itself can be executed in SQL Management Studio without any problems.

What i know:

I found out through the XPS Profiler that the ODBC driver makes the following from the statement:

declare @p1 int set @p1=0 declare @p3 int set @p3=8 declare @p4 int set @p4=8193 declare @p5 int set @p5=0 exec sp_cursoropen @p1 output,N'exec xp_msver ''ProductVersion''',@p3 output,@p4 output,@p5 output select @p1, @p3, @p4, @p5.

This actually reproduces the problem. If I execute a statement like

declare @p1 int set @p1=0 declare @p3 int set @p3=8 declare @p4 int set @p4=8193 declare @p5 int set @p5=0 exec sp_cursoropen @p1 output,N'select GENERICCOLUMN from GENERICTABLE',@p3 output,@p4 output,@p5 output select @p1, @p3, @p4, @p5.

it works without any problems.

Question:

Does anyone know why the error occurs or does anyone know a workaround?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,492 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Naomi Nosonovsky 8,291 Reputation points
    2024-08-12T13:41:44.69+00:00

    May be you can try instead:

    SELECT 
    SERVERPROPERTY('Edition') AS Edition,
    SERVERPROPERTY('ProductVersion') AS ProductVersion,
    SERVERPROPERTY('ProductLevel') AS ProductLevel
    
    0 comments No comments

  2. Erland Sommarskog 119.9K Reputation points MVP
    2024-08-12T21:31:49.91+00:00

    Sounds like you are calling the stored procedure in the wrong way. My ODBC is rusty, but I think you should use SQLExecDirect. You should certainly not have any cursor.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.