Click here to Skip to main content
16,006,013 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CLSID's Pin
Anders Molin14-Oct-01 7:21
professionalAnders Molin14-Oct-01 7:21 
GeneralRe: CLSID's Pin
#realJSOP15-Oct-01 5:13
professional#realJSOP15-Oct-01 5:13 
GeneralVariable Init Pin
13-Oct-01 0:48
suss13-Oct-01 0:48 
GeneralRe: Variable Init Pin
NormDroid13-Oct-01 2:13
professionalNormDroid13-Oct-01 2:13 
GeneralThanks Pin
13-Oct-01 2:20
suss13-Oct-01 2:20 
GeneralRe: Thanks Pin
Sijin13-Oct-01 2:27
Sijin13-Oct-01 2:27 
GeneralRe: Variable Init Pin
Sijin13-Oct-01 2:25
Sijin13-Oct-01 2:25 
GeneralADO/ADOX Hell Pin
Christian Graus12-Oct-01 19:59
protectorChristian Graus12-Oct-01 19:59 
I have a progrma now that uses ADO to read/modify/add to and delete records from a database.

My problem is two fold. First of all I want to create the database programatically, so I import ADOX like this:

#import "c:\Program Files\Common Files\System\ADO\msadox.dll"  rename ("EOF", "adoxEOF")


Then I do this to create the database

HRESULT hr = S_OK;

// Define ADOX object pointers.
// Initialize pointers on define.
// These are in the ADOX::  namespace.
ADOX::_CatalogPtr m_pCatalog = NULL;
ADOX::_TablePtr   m_pTable   = NULL;

try
{
    TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));

    char * pChar = new char[400];
    memset(pChar, 0, 400);
    sprintf(pChar, "Provider=Microsoft.JET.OLEDB.4.0;data source=%s;", (char*)DatabasePath);

    //Open the catalog
    m_pCatalog->Create(pChar);
    delete [] pChar;

    TESTHR(hr = m_pTable.CreateInstance(__uuidof(ADOX::Table)));
    m_pTable->PutName("FileDatabase");
    m_pTable->Columns->Append("FileName",ADOX::adVarWChar, 255);
    m_pTable->Columns->Append("FilePath",ADOX::adVarWChar,255);
    m_pTable->Columns->Append("FileLength",ADOX::adInteger,0);
    m_pTable->Columns->Append("TimesDownloaded",ADOX::adInteger,0);
    m_pTable->Columns->Append("LastModified",ADOX::adInteger,0);
    m_pTable->Columns->Append("Frames",ADOX::adInteger,0);
    m_pTable->Columns->Append("Seconds",ADOX::adInteger,0);
    m_pTable->Columns->Append("Width",ADOX::adInteger,0);
    m_pTable->Columns->Append("Height",ADOX::adInteger,0);
    m_pCatalog->Tables->Append(
        _variant_t((IDispatch *)m_pTable));

    m_pCatalog->Tables->Refresh();
}

catch(_com_error &e)
{
    // Notify the user of errors if any.
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());

    MessageBox(NULL, bstrDescription, bstrSource, 0);

    return E_FAIL;
}

catch (...)
{
    MessageBox(NULL, "General Error Creating Database", "Error", 0);
    return E_FAIL;
}

return S_OK;


This works up to a point - the point I try to use it. It returns no errors and creates a file but neither my code or Access 2000 can read it. The other problem is if I create an empty table ( using Access ) this fails:

m_Connection.CreateInstance(__uuidof(Connection));

CComBSTR conStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
conStr.Append(DatabasePath);

bstr_t con(conStr);

HRESULT hr = (m_Connection->Open(con, "", "", adConnectUnspecified));


As soon as I add one dummy record, it succeeds.

So for now I must ship the Access DB with the program, I cannot create it, and the DB programatically ensures a dummy (meaningless) record exists and is hidden from the user. Surely this is not how it is supposed to work, so what am I doing wrong ?

Thanks


Christian

As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.

Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
GeneralRe: ADO/ADOX Hell Pin
Christian Graus13-Oct-01 1:24
protectorChristian Graus13-Oct-01 1:24 
QuestionHow can I make an arbitrary row from a simple CListBox unselectable, but still viewable? Pin
DanYELL12-Oct-01 11:44
DanYELL12-Oct-01 11:44 
AnswerRe: How can I make an arbitrary row from a simple CListBox unselectable, but still viewable? Pin
Bill Wilson12-Oct-01 13:59
Bill Wilson12-Oct-01 13:59 
AnswerRe: How can I make an arbitrary row from a simple CListBox unselectable, but still viewable? Pin
13-Oct-01 7:13
suss13-Oct-01 7:13 
GeneralIActiveDesktop Problem (not a creation problem) Pin
12-Oct-01 10:03
suss12-Oct-01 10:03 
GeneralRe: IActiveDesktop Problem (not a creation problem) Pin
mkaltner12-Oct-01 10:16
mkaltner12-Oct-01 10:16 
GeneralRe: IActiveDesktop Problem (not a creation problem) Pin
PJ Arends12-Oct-01 10:44
professionalPJ Arends12-Oct-01 10:44 
GeneralRe: IActiveDesktop Problem (not a creation problem) Pin
mkaltner12-Oct-01 10:54
mkaltner12-Oct-01 10:54 
QuestionHow do I execute Oracle stored procedures from ADO in Visual C++? Pin
Hojo12-Oct-01 9:19
Hojo12-Oct-01 9:19 
AnswerRe: How do I execute Oracle stored procedures from ADO in Visual C++? Pin
Michael P Butler13-Oct-01 2:02
Michael P Butler13-Oct-01 2:02 
AnswerRe: How do I execute Oracle stored procedures from ADO in Visual C++? Pin
NormDroid13-Oct-01 5:03
professionalNormDroid13-Oct-01 5:03 
Generalnetmeeting 3 automation Pin
aniel12-Oct-01 9:15
aniel12-Oct-01 9:15 
QuestionWinsock? Pin
12-Oct-01 7:53
suss12-Oct-01 7:53 
AnswerRe: Winsock? Pin
Nemanja Trifunovic12-Oct-01 8:03
Nemanja Trifunovic12-Oct-01 8:03 
GeneralRe: Winsock? Pin
12-Oct-01 8:41
suss12-Oct-01 8:41 
GeneralRe: Winsock? Pin
Nemanja Trifunovic12-Oct-01 8:47
Nemanja Trifunovic12-Oct-01 8:47 
AnswerRe: WinInet! Pin
Masaaki Onishi12-Oct-01 9:14
Masaaki Onishi12-Oct-01 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.