Link to home
Start Free TrialLog in
Avatar of Dave Roger
Dave RogerFlag for United States of America

asked on

Heterogeneous Queries, Linked servers, Crystal

I have written a stored procedure  Crystal report.  The stored proc has a select..... with  an inner join to a linked server table (not a view).   I create the SP with the setting of ANSI_NULLS and ANSI_WARNINGS ON as most of the threads here say to do.  The SP runs great in SSMS (Management studio).     But when I go to run it in Crystal, I get the familair "Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection....."
I have gone to the server I am linking to, and set the instance > properties > connections, and checked ansi warnings and ansi nulls.    still get the error.

This is all running under SQL Server 2012 (Express)  64 bit.
SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Roger

ASKER

Hi,

it IS in the SP create:

SET ANSI_NULLS ON
set ansi_warnings on
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROC [dbo].[p_....]

Again, the proc runs OK if I run it in SQLManagement Studio.  It does not run from Crystal XI
Can you check in there's a why to configure the connection from CR to MSSQL to SET ANSI_NULLS ON and SET ANSI_WARNINGS ON?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will try the SP - calling an SP approach.
I'm wondering if the SP should select from a view?
Avatar of James0628
James0628

> I'm wondering if the SP should select from a view?

 Honestly, I have no idea.  I never used views much (I didn't have anything against them.  I just didn't use them).  So I really don't know if that will make a difference.

 James
Nope, even using a view instead of a stored procedure still got me the heterogeneous error.  it's definitely something with how Crystal is using or calling the db and the linked sevrer in particular.  

OK, gonna try the temp table route next.
OK, so I did an SP that sleelcts from the "home" server and the linked server the data I need, and it writes to a ##temp table.  Then I have an "enveloping" SP that calls this first one, and then returns the results of the select * from ##temp.

It runs great in SSMS.  but, dammit, if Crystal still bombs looking for the heterogeneous query looking for ansi nulls and ansi warnings.

I wonder if there were options in the creation of the linked server that need to be set?
Vitor,

you say

<Can you check in there's a why to configure the connection from CR to MSSQL to SET ANSI_NULLS ON and SET ANSI_WARNINGS ON?>

I'd love to! do any experts out there know how to check the connection?  

It's an ODBC connection
I heard about something called Database Expert in Crystal Reports where you can do something like this:
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON

exec SP_NameHere {@Param1}, {@Param2}

Open in new window

It runs great in SSMS.  but, dammit, if Crystal still bombs looking for the heterogeneous query looking for ansi nulls and ansi warnings.

 I'm not sure what else to tell you.  I sounds like you're doing the same thing, and it worked for me, but, FWIW, that was years ago.

 You could try Vitor's suggestion.  You can create a "Command" in CR, which is just a query that you enter manually, and apparently you can execute a SP from a Command.  Unfortunately, changing the datasource like that may require recreating the report from scratch.  I'm not sure.

 IAC, to test the idea, you could create a new report, use "Create New Connection", select your db connection and there should be an "Add Command" option.  That should open the Command editor window, where you would enter something like the lines that Vitor posted.  Note that if the SP has any parameters, the corresponding report paramaters should be created in that window.  Unless CR has changed, you can only use parameters in a Command that were created in the Command editor.  Once you've created a parameter, you can double-click on it to add it to the Command.

 Then I guess you'd just need to save the Command, put some fields on the report and try running it.

 James
I will try these things.  
I am wondering if the creation of the Linked Server needed to have these ANSI parameters set.  That seems to be the place where Crystal is falling over.    It's the Linked Server.     But what I don't know is how to either delete and re-create with proper parameters, or somehow have Crystal "override" these linked server parameters so that it's happy.
You can try to create the linked server inside the SP but I don't know if it will helps:
exec sp_addlinkedserver
@server = 'ServerName\InstanceName',
@srvproduct=N'',
@provider=N'SQLNCLI'

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mike,

You did it again.  Thanks.

Yes, it was the ODBC.  So a few things:
1).  I tried setting BOTH ANSI boxes in the ODBC early on, and still had the failure.   But I think that was prior to setting the ANSI's in the SP create.  
2).  The same ODBC works fine in many other Crystals I have.  This is the first, however, with a linked server table join.
3). I ONLY set the ODBC "Use ANSI nulls, paddings and warnings.  
report runs!

thank you all.