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.