Saturday, February 25, 2012

ODBC Program & Heterogeneous queries problem

Best All,

What I am doing is following:
1. I created a stored procedure "testit" which select records from another data source in another SQL Server, like:

------------
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
go

create procedure testit
as begin
select * from [AnotherSQLServer].bugtest.dbo.mssent
end

grant execute on testit to public
------------

2. I can execute this stored procedure in SQL Query Analyser with success.

3. BUT: now I write a ODBC program trying to call this stored procedure, then it give me following "famous" error:
42000 [Microsoft][ODBC SQL Server Driver][SQL Server]Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.

The ODBC program looks like this:
--------
strcpy((char *) sqltext, "{call testit}");
rc = SQLPrepare(hstmt, (unsigned char *) sqltext, SQL_NTS);
rc = SQLExecute(hstmt);
--------

My Question:
1. Does ODBC API support Heterogeneous queries ?
2. If well, how to solve above problem?

Thanks a lot,

MelThe solution can be found here:

http://dbforums.com/t905850.html

use some thing like this (before calling SQLConnect() ):
SQLSetConnectAttr( hdbc,SQL_COPT_SS_ANSI_NPW,(void *) SQL_AD_ON, 0);

No comments:

Post a Comment