Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2005, 06:10 AM
Registered User
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Crystal datasource changing from Access to SQL and

Hello!

I have a vb6 app that can run on either and Access or a SQL server database depending on which the client required...

I have created one set of crystal reports that I wish to run off both databases - depending on where the ODBC is pointing at. The trouble is that I have to go back into the crystal report and do a 'set location' every time i want the report to swap from access to SQL - even though the PDBC is called the same and the databases are physically identical.

Can i send through a connectionstring at view-time or something? Any ideas?

Sorry if this is confusing or if i have posted this in the wrong place!?

Tabilda
 
Old November 23rd, 2005, 02:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You need to apply the logon information to each table in your report. The following code does that:
Code:
myReport = new YourReportType();
SetLogonInfo(myReport);

private void SetLogonInfo(ReportClass myReport)
{
  CrystalDecisions.Shared.ConnectionInfo myDbConnectionInfo = 
          new CrystalDecisions.Shared.ConnectionInfo();
  myDbConnectionInfo.ServerName = "YourServerNameOrIp";
  myDbConnectionInfo.DatabaseName = "YourDatabase";

  myDbConnectionInfo.UserID = "UserName";
  myDbConnectionInfo.Password = "Password";

  CrystalDecisions.Shared.TableLogOnInfo myTableLogonInfo = 
           new CrystalDecisions.Shared.TableLogOnInfo();
  CrystalDecisions.CrystalReports.Engine.Database myDatabase = myReport.Database;
  CrystalDecisions.CrystalReports.Engine.Tables myTables  = myDatabase.Tables;
  foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in myTables)
  {
    myTableLogonInfo = myTable.LogOnInfo;
    myTableLogonInfo.ConnectionInfo = myDbConnectionInfo;
    myTable.ApplyLogOnInfo(myTableLogonInfo);
  }
}
There may be better / quicker or easier ways to do this, but I am not aware of them. This has always worked for me. I think you can leave out the UserID and Password properties of the ConnectionInfo object for integrated security.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 24th, 2005, 05:32 AM
Registered User
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar - thank you for your reply!

Is this VB6 code? Also - for the access version of the crystal report i dont have a server name etc.. I am also talking about hundreds of tables!!

Thanks, Tabilda.

 
Old November 24th, 2005, 06:55 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ooops, sorry, no. This is C# code and only works in a .NET project. Overlooked you were using VB 6.

I never worked with VB6 and Crystal reports, so I don't know how to do this in VB6. Sorry. Maybe Googling for ApplyLogOnInfo and VB6 brings up something useful....


Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 24th, 2005, 09:57 AM
Registered User
 
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh well never mind - maybe i will just maintain 2 sets of reports!!!

Thanks for your help though, tabilda.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable crystal report datasource dialogbox owen_xgy .NET Framework 2.0 2 November 21st, 2008 07:44 AM
Change datasource of crystal report at runtime check123 Pro VB 6 1 March 21st, 2008 05:45 AM
change Datasource of a crystal report at run time tiyyob Pro VB 6 1 February 17th, 2007 06:05 AM
changing sql query of crystal reports from program connect2sandep Crystal Reports 1 August 22nd, 2006 01:15 PM
Changing Datasource khattard SQL Server DTS 1 January 30th, 2004 11:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.