I am wrote the following code for creating the MDB file, creating the
TABLES and fields dynamically in an
MFC dialog bases application.
The problem is that I get access violation exception after executing
the adocommand.Execute(NULL, NULL, 1) function.
void foo()
{
DeleteFile("c:\\new.mdb");
OleInitialize(NULL);
_Catalog catalog;
if(!catalog.CreateDispatch("ADOX.Catalog.2.5"))
{
return;
}
//Set ActiveConnection of Catalog to this string
CString sTest("Provider=Microsoft.JET.OLEDB.4.0;""Data source =
c:\\new.mdb");
catalog.Create(sTest);
_Command adocommand;
if(!adocommand.CreateDispatch("ADODB.Command.2.5"))
{
return;
}
VARIANT var = catalog.GetActiveConnection();
adocommand.SetActiveConnection(var);
CString sSQL("CREATE TABLE ATTRIB (OfficeId TEXT(20),
OfficeName TEXT(10))");
adocommand.SetCommandText(sSQL);
adocommand.Execute(NULL, NULL, 1);
//Here I get access violation
adocommand.ReleaseDispatch();
catalog.ReleaseDispatch();
OleUninitialize();
Quote:
}
I need some help to resolve this.
Thanks
-George
Sent via Deja.com http://www.*-*-*.com/
Before you buy.