Click to See Complete Forum and Search --> : Urgent!!!An ADOX program used by Remote client


bala.narne
August 18th, 2000, 07:32 AM
Hi,
I am writing a ATL com component which will be used by other
computer in network that is a DCOM component.
The requirement is to create a .mdb file programmatically using ADOX.
The requirement is that I should not create a DSN statically.
The code is as follows in FinalConstruct function:

member variables:
------------------------
ADODB::_ConnectionPtr m_pconnection;
_CatalogPtr m_pCatalog;
----------------------
m_pCatalog = NULL;
_TablePtr m_pTable = NULL;
_variant_t var;


//Set ActiveConnection of Catalog to this string
_bstr_t strcnn("Provider=Microsoft.JET.OLEDB.4.0;"
"Data source = c:\\com\\AdoServer4\\new.mdb");
try
{
hr = m_pCatalog.CreateInstance(__uuidof (Catalog));
// Create .mdb file dynamically
var = m_pCatalog->Create(strcnn);

//Open the catalog
m_pCatalog->PutActiveConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;" \
"data source=c:\\com\\AdoServer4\\new.mdb;");
hr = m_pTable.CreateInstance(__uuidof(Table));
}

The problem is when I register component in other computer and execute
client program then I will get error -
Invalid Path c:\\com\\AdoServer4\\new.mdb.
Thus failing CoCreateInstanceEx.
How do I solve this problem?

Johnny101
August 18th, 2000, 11:13 AM
I'm not a C++ guy, but I am very willing to bet that the error is because the directory path you used to compile your component doesn't exist on the target machine. In Visual Basic there is something called the App object - it holds things like the path to itself. For example: If i place my app in the c:\program files\company stuff\ folder - that's what the App.Path property will return. then in my code i can reference this property to get a full path to a file in the same directory - App.Path & "\filename.mdb" (the full path is now C:\program files\company stuff\filename.mdb). If you have something like that in VC - that's what you need to use here. instead of hardcoding the path of c:\\com\\AdoServer4\\new.mdb - try the app.path & "\new.mdb" approach. it should help. i've seen this exact scenario on the VB side as well, and this fixed it.

hope this helps,

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

bala.narne
August 19th, 2000, 12:05 AM
Hi John,
Thank you for going through the problem.
In vc++, there is no apppath etc.
If there is any other way without giving path of .mdl file then it will be helpful

bala.narne
August 19th, 2000, 12:08 AM
Hi John,
Thank you for going through the problem.
In vc++, there is no apppath etc.
If there is any other way without giving path of .mdl file then it will be helpful

Johnny101
August 21st, 2000, 12:11 PM
at this point - i can only suggestion going to the C++ forum and asking someone there how to get to the current directory path to the exe. Some of them may know about VB's App.Path object - so be sure to mention to them that is what you are after.

good luck,

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org