Data Connectivity
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Data Connectivity
Message Icon Topic: SQL Server View connection Post Reply Post New Topic
Author Message
GHustis
Newbie
Newbie
Avatar

Joined: 25 Oct 2012
Location: United States
Online Status: Offline
Posts: 3
Quote GHustis Replybullet Topic: SQL Server View connection
    Posted: 16 Nov 2012 at 10:55am

I have a Crystal XIr2 Report that reports on data from a SQL Server VIEW. Using the Database expert I created a connection to that view & inserted the fields. (Actually this report, as are about 75 others, are being upgraded from CR V7 but the same concept applies).

The problem I'm encountering is that the DataBase Expert is creating a fully qualified link to my test database that I can't seem to change at run time. The other reports that report on data from tables don't seem to have this problem.

When using the Show SQL Query option in CR is shows the Select statement as I'd expect. but the From Clause shows:  FROM   "TESTDB"."dbo"."FullPallet" "FullPallet"

For my other reports that report on tables only the From clause would show something similar to:  FROM   "Table1l" "Table1"

Since this app is deployed to multiple customers their servers and DBs will have varying names so at run time i send a connection string that works for all the other reports expect the ones that report on VIEWS. The connection string is thus: crReport.Database.Tables(1).SetLogOnInfo SqlServerName$, SqlCatalogName$, "UserID", "Password"

If i connect my app to a different DB on the same SQL server the report will find the TestDB & try to report on it. Obviously producing erroneous data. If i connect to a different SQL Server that has no TestDB, it produces an error that it can not find my TestDB.

I also tried to replace the report's SQL Statement by sending my own to it using:

crReport.SQLQueryString = "SELECT FullPallet.ShipOrder, FullPallet.SeqNum, FullPallet.Description FROM FullPallet FullPallet"

(FullPallet is the name of the View)

and it still fails on looking for the TestDB.

BTW - the reports are being called from a VB6 app, if that helps any.

So any help would be greatly appreciated.



Edited by GHustis - 16 Nov 2012 at 10:58am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Nov 2012 at 10:43am
Instead of setting the SQLQueryString in code, I would try creating a command as the data source for the report instead of using tables/views in the report design.  A command is simply a SQL select statement that returns all of the data that the report needs from all of the tables or views required.  In other words, you don't want to replace each table or view with a command and then link the commands together.  Instead you need to put all of the joins into a single select statement and use that as a command. 
If you're using parameters to filter the data for the report, create them in the Command Editor NOT in the report itself.  You would then use the parameters like this:
 
table.stringfield = '{?string param}' and
table.numberfield = {?number param} and
table.datefield = {?date param}
 
-Dell
IP IP Logged
GHustis
Newbie
Newbie
Avatar

Joined: 25 Oct 2012
Location: United States
Online Status: Offline
Posts: 3
Quote GHustis Replybullet Posted: 20 Nov 2012 at 5:52am
Dell,
Your reply caused me to have a ton of questions. I did a little reading on the command idea and I think I will pursue it.
However my immediate concern is to do one thing and that is to point my reports to an SQL Server & DataBase that the app is pointing to. I have nearly 100 reports written in CR7 called by a VB6 app that I am converting to CR XIr2 to run on Windows 7. (a .NET conversion will come later where I'll probably take up the Command issue).
Since I have to do this as fast as possible I want to make as few changes as needed to get this done.
From my research on this It seems as though I need to set the Location of the Server & DB in code, but am having trouble figuring out how to do this.
All the examples i find on the net show me how to set the location of an MS Access DB.
Initially i was using just this one line of code to set it and it seemed to work fine except for a few reports, even if there were multiple tables in the report:
crReport.Database.Tables(1).SetLogOnInfo SqlServerName$, SqlCatalogName$, "UserID", "Password"
Where crReport =CRAXDRT.Report
I found another example to loop through all the tables in the report & set each table's Logon info, It too didn't solve my problem.
Since this app is at multiple customers where their Servers & DB's are named differently, I need to be able to pass this information to the report.
Thanks for any help you can provide.
Gary

 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 20 Nov 2012 at 6:26am
Unfortunately, with the upgrade to XI, you probably have no choice but to go the command route.  The internal structure of the .rpt file changed drammatically with version 9 of Crystal and there is no way to override the fully qualified domain name.
 
Have you tested the reports after you converted them?  From personal experience, I suspect that the query was edited in the original Crystal 7 reports to remove the database.owner and leave just the table or view name.  If that's the case, and you've just opened the report in Crystal XI r2 and then saved it as the new version, then the report is not going to work correctly to begin with.  When I did this with Crystal 8.5 reports where we had done this exact kind of edit, it looked like the tables and joins were set up correctly in XI, but the generated SQL had no joins an brought back data that was a cartesian product.  I ended up having to recreate the reports from scratch in XI.  What I'm saying here is that you may end up having to edit the reports anyways in order to get them to actually work in XI.
 
-Dell
IP IP Logged
GHustis
Newbie
Newbie
Avatar

Joined: 25 Oct 2012
Location: United States
Online Status: Offline
Posts: 3
Quote GHustis Replybullet Posted: 20 Nov 2012 at 8:25am
Dell,
You just gave me the path to my solution. I opened the report in CR7 & in the Set Location window I removed the reference to the Database name leaving only the Table name (in this case a View) and saved it. I then opened & saved it in CR XI. The reference to the database name is removed & my SetLogOnInfo now directs the report to the database named there.
Thanks for your Sage advice, even if you weren't aware of what advice you were giving.
Gary.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.017 seconds.