This question is part in a series of bugs in the Microsoft ODBC driver:
- ODBC driver fails to raise errors; but instead suppresses them
- Reading columns out of order returns incorrect results
- Cannot execute a stored procedure that is a SYNONYM
Microsoft has said they will not be fixing these bugs in their ODBC driver.
I have (many) stored procedures that are actually synonyms. The stored procedure exists canonically in one database, but are visible in others.
The stored procedure executes fine from within SQL Server Management Studio:
EXECUTE Report_ThirdParty @ContosoGUID = '{CC0ECA32-BEFA-11E5-8E2A-C86000D0B92A}'
And if I connect to SQL Server using any OLEDB provider:
- SQL Server Native Client 10.0 OLE DB Provider:
Provider=SQLNCLI10;Data Source=contoso.stackoverflow.com;User ID=ContosoManager;Password=correct horse battery staple;
- Microsoft OLE DB Provider for SQL Server:
Provider=SQLOLEDB;Data Source=contoso.stackoverflow.com;User ID=contoso.stackoverflow.com;Password=correct horse battery staple;
Then the stored procedure executes fine. I get results. And everyone's happy.
But not with the ODBC driver
With the announcement of the deprecation of OleDb drivers, I wanted to test using the ODBC drivers for SQL Server. When I change the connection to use one of the SQL Server ODBC drivers (e.g. "{SQL Server}") and execute the same SQL statement
EXECUTE Report_ThirdParty @ContosoGUID = '{CC0ECA32-BEFA-11E5-8E2A-C86000D0B92A}'
I get the error:
The request for procedure 'Report_ThirdParty' failed because 'Report_ThirdParty' is a synonym object
This is true whether I use the original ODBC driver for SQL Server, or the native client:
SQL Server:
Provider=MSDASQL;Driver={SQL Server};Server={contoso.stackoverflow.com};UID={contosoManager};PWD={correct horse battery staple};
SQL Server Native Client 11.0:
Provider=MSDASQL;Driver={SQL Server Native Client 11.0};Server={contoso.stackoverflow.com};UID={ContosoManager};PWD={correct horse battery staple};
In both variations i get the same error:
[Microsoft][SQL Server Native Client 11.0][SQL Server]The request for procedure 'Report_ThirdParty' failed because 'Report_ThirdParty' is a synonym object
or for the older ODBC driver:
[Microsoft][ODBC SQL Server Driver][SQL Server]The request for procedure 'Report_ThirdParty' failed because 'Report_ThirdParty' is a synonym object
In other words:
The request for procedure '%s' failed because '%s' is a synonym object
The Errors
collection of the Connection provides more information:
Error#1
- Number: 0x80040E14
- Source: Microsoft OLE DB Provider for ODBC Drivers
- Description: [Microsoft][ODBC SQL Server Driver][SQL Server]The request for procedure 'Report_ThirdParty' failed because 'Report_ThirdParty' is a synonym object.
- SQLState: 37000
- NativeError: 2809
Error#2
- Number: 0x80040E14
- Source: Microsoft OLE DB Provider for ODBC Drivers
- Description: [Microsoft][ODBC SQL Server Driver][SQL Server]The cursor was not declared.
- SQLState: 37000
- NativeError: 16945
There's no harm in abandoning the switch to ODBC. And I'm not going to stop using synonyms.
But what is wrong, and how do i tell the ODBC Driver for SQL Server to work?
The SQL Profiler results
- RPC:Starting: declare @p1 int set @p1=0 declare @p3 int set @p3=16388 declare @p4 int set @p4=8193 declare @p5 int set @p5=0 exec sp_cursoropen @p1 output,N'EXECUTE Report_ThirdParty @ContosoGUID = ''{3492C4E6-D500-4A23-9CAB-CB6582C27ABD}''',@p3 output,@p4 output,@p5 output select @p1, @p3, @p4, @p5
- Exception: Error: 2809, Severity: 18, State: 1
- User Error Message: The request for procedure 'Report_ThirdParty' failed because 'Report_ThirdParty' is a synonym object.
- Exception: Error: 16945, Severity: 16, State: 2
- User Error Message: The cursor was not declared.
- RPC:Completed: : declare @p1 int set @p1=0 declare @p3 int set @p3=16388 declare @p4 int set @p4=8193 declare @p5 int set @p5=0 exec sp_cursoropen @p1 output,N'EXECUTE Report_ThirdParty @ContosoGUID = ''{3492C4E6-D500-4A23-9CAB-CB6582C27ABD}''',@p3 output,@p4 output,@p5 output select @p1, @p3, @p4, @p5
Notes
- Native (i.e. not .NET) code. You can pretend it's C, C++, assembly, or Delphi.
- Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
Other unintended features of ODBC (that work in OLEDB)
- Stackoverflow: Reading columns out of order returns incorrect results
- Stackoverflow: Cannot execute a stored procedure that is a SYNONYM
- Stackoverflow: ODBC driver suppresses errors