Data Connectivity
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Data Connectivity
Message Icon Topic: How can I read a report's connection properties? Post Reply Post New Topic
Author Message
RobR
Newbie
Newbie


Joined: 24 Apr 2009
Location: United States
Online Status: Offline
Posts: 18
Quote RobR Replybullet Topic: How can I read a report's connection properties?
    Posted: 13 Jul 2009 at 6:53am
Greetings!
 
Here's the question, so you don't have to wade through the junk below if you don't want to:
 
I'm working in MS Visual C++ 6.  I am not expert in working with COM-related objects and structures.  Can someone please give me a sample of code that will let me read a report's database connection properties?
 
 
Now, here's why I want to know:
 
We will not know until run time what database a report needs to retrieve its data from.  I once found an article on line that discussed how to change a report's target database at run time.  It explained the technique we are actually using.  Here's the code that does it for us:
 
  // Now we have to tell the table how to connect to the database we need it to connect to.
  // To do that, we'll get rid of everything the table knows about its database and replace
  // it with everything that is known about the connection we passed in to this method.
  m_Report->Database->Tables->GetItem(tableIndex)->ConnectionProperties->DeleteAll();
  long tcp_index = 1;
  
 
  for (ConnPropertyConstIter iter = propertyMap.begin(); iter != propertyMap.end(); iter++)
  {
   Name = iter->first;
   Value = iter->second;
   m_Report->Database->Tables->GetItem(tableIndex)->ConnectionProperties->Add(Name.AllocSysString(), Value);
  }
We blow away all of the report's database connecton properties and replace them with the properties for the current database connection (which were read earlier into an STL map). 
 
But this process is slow.  Sometimes it's exceedingly slow.  I would like to avoid it if possible.  I tried stubbing out the function that contains this code.  When our application is looking at the database the report expects, there is no problem.  The report appears as expected.  But if the application is looking at Database B but the report was developed using Database A, and both databases still exist, then the information displayed in the report is from A, not B. 
 
99% of the time, the report will be set up to look at a database with the same name as the one it was developed against, and we don't have to change anything.  So, before I change things, I would like to know the database name the report is expecting.  I have tried a couple of times to write code that will look at the ConnectionProperties collections, but it requires more COM expertise than I have. 
Richardson's First Law of Computational Unpredictability: The fact that a given occurrence is impossible does not imply that it will not occur.
IP IP Logged
RobR
Newbie
Newbie


Joined: 24 Apr 2009
Location: United States
Online Status: Offline
Posts: 18
Quote RobR Replybullet Posted: 13 Jul 2009 at 10:01am

As often happens, I realized that I asked the wrong question.  The correct question is much simpler:  How can I find out what database the report is expecting?  It turns out that the answer is simple.  Table objects have a property named "ConnectBufferString".  This string is a simple connection string, consisting of a series of name=value pairs separated by semicolons.  All I have to do is to parse that string to determine if the database needs to be changed for that table.

RobR

Richardson's First Law of Computational Unpredictability: The fact that a given occurrence is impossible does not imply that it will not occur.
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.047 seconds.