Database connection...

This is a discussion on Database connection... within the Windows Programming forums, part of the Platform Specific Boards category; I have this code which should connect to a MS Access database and output the string values of "table´".. Well ...

  1. #1
    the Wizard
    Join Date
    Aug 2004
    Posts
    109

    Database connection...

    I have this code which should connect to a MS Access database and output the string values of "table´".. Well see for yourself

    Code:
    #include <stdio.h>
    #include "E:\Program Files\Microsoft Visual Studio\VC98\mfc\SRC\stdafx.h"
    #import "c:\program files\common files\system\ado\msado15.dll" rename("EOF", "EOFile")
    struct StartOLEProcess {
    StartOLEProcess() {
    ::CoInitialize(NULL); 
    }
    ~StartOLEProcess() {
    ::CoUninitialize();
    }
    } _start_StartOLEProcess;
    int main() {
    ADODB::_ConnectionPtr Con = NULL;
    ADODB::_RecordsetPtr RecSet = NULL;
    ADODB::FieldPtr pStrings;
     
    _variant_t vStrings;
    char sStrings[150];
    HRESULT hr = S_OK;
    VARIANT *RecordsAffected = NULL;
    hr = Con.CreateInstance(__uuidof(ADODB::Connection));
    printf("\nCreateInstance result=%d uuidof=%d\n", hr, __uuidof(ADODB::Connection));
    printf("\nConnection object created.");
     
    Con->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\database.mdb", "", "password", 0);
     
    printf("\nConnection opened...");
    RecSet = Con->Execute("SELECT * FROM strings", RecordsAffected, 1);
    printf("\nSQL statement processed");
     
    pStrings = RecSet->Fields->GetItem(Table);
    printf("\nGetting data now...\n");
     
    while(!RecSet->EOFile) {
    vStrings.Clear();
    vStrings = pQuestions->Value;
    WideCharToMultiByte(CP_ACP, 0, vStrings.bstrVal, -1, sStrings, sizeof(sStrings), NULL, NULL);
    printf("\n%s", sStrings);
    RecSet->MoveNext();
    }
    printf("\n\nEnd of data..");
    RecSet->Close();
    RecSet = NULL;
    printf("\nClosed and removed recordset object.");
    Con->Close();
    Con = NULL;
    printf("\nClosed and removed connection object.");
    return 0;
    }
    I can compile it okey, but with one warning:

    Code:
    Compiling...
    main.cpp
    d:\c++\database\debug\msado15.tlh(409) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
    Linking...
    database.exe - 0 error(s), 1 warning(s)
    so it compiles okey, and then when I try to run the program, the following output comes:

    Code:
    D:\C++\database\Debug>database.exe
    CreateInstance result=0 uuidof=1300
    Connection object created.
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    Does somebody have a solution to my problem?

    Thx in advance
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    1
    I wish I could help pal, but that's just beyond me.

    As a matter of fact, I'm a newbie to C/C++/C# programming.

  3. #3
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    That's okey

    I'll get better, practice makes better
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  4. #4
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    But if any of you have a solution to my problem or any kind of help.. Just write please

    Thx in advance
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 02:09 PM
  2. oracle database connection
    By blue8173 in forum C Programming
    Replies: 1
    Last Post: 03-16-2004, 04:30 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM
  4. database application help.
    By Billy Baroo in forum Linux Programming
    Replies: 1
    Last Post: 09-02-2002, 07:23 PM
  5. connection to database through c++
    By teja22 in forum C++ Programming
    Replies: 1
    Last Post: 10-15-2001, 05:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21