🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #4124

Sample : connect to database Access - what`s wrong this code?

#4124
From: Slava Sh.
Date: Thu, 21 Mar 2002 11:12
165 lines
5444 bytes
SOS ! ( . . .  _ _ _ . . .)

Help !!!


VARIANT1
~~~~~~~~~

Working code:
===========

void __fastcall TForm1::Button1Click(TObject *Sender)
{
//
//  ����������
//
     try
     {
       if(DM->ADOConnection->Connected == true)
       {
        DM->ADOConnection->Close();
       }

        DM->ADOConnection->ConnectionTimeout = 15;
        DM->ADOConnection->LoginPrompt = false;
//
      ConnectionString =

    "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data
Source=C:\\WORK\\C_Project\\BCB5\\testADO\\Data\\cat22.mdb";

//
        DM->ADOConnection->ConnectionString = ConnectionString;

//
        DM->ADOConnection->Open("Admin", "");
//
        DM->CATADOTable->Connection = DM->ADOConnection;
        DM->CATADOTable->Open();
        DM->RISADOTable->Connection = DM->ADOConnection;
        DM->RISADOTable->Open();
        DM->DETADOTable->Connection = DM->ADOConnection;
        DM->DETADOTable->Open();
        DM->SEDADOTable->Connection = DM->ADOConnection;
        DM->SEDADOTable->Open();
        DM->UZLADOTable->Connection = DM->ADOConnection;
        DM->UZLADOTable->Open();
    }
     catch(EOleException &E)
     {
      Application->MessageBox(
      "��������� �������������� �������� ��� ���������� � ����� ������ !",
      "����������� ������",
      MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL);
     }
}



VARIANT2:
~~~~~~~~~

NOT WORKING CODE (ERROR -> "C:\WORK\C_Project\BCB5\testADO\Data\cat22.mdb'
is not valid path)
============================================================================
====
note: path exist !!!


void __fastcall TForm1::Button1Click(TObject *Sender)
{
//
//  ����������
//
     try
     {
       if(DM->ADOConnection->Connected == true)
       {
        DM->ADOConnection->Close();
       }

        DM->ADOConnection->ConnectionTimeout = 15;
        DM->ADOConnection->LoginPrompt = false;
//
// Get current Dir
//
        GetCurrentDirectory(MAX_PATH, CurPath);

        PathToDatabase = ExtractFilePath(CurPath) + "\Data";
        FileNameOfDatabase = "cat22.mdb";
        PathToDatabase += "\\" + FileNameOfDatabase;

        CurPath[0] = '\0';
        strcpy(CurPath, PathToDatabase.c_str());

        TempPath[0] = '\0';

        int j = 0;
//
// add '\' + '\'
//
        for(int i = 0; i <= strlen(CurPath) - 1; i++)
        {
         TempPath[j] = CurPath[i];

         if(TempPath[j] == '\\')
         {
          j++;
          strcat(TempPath, "\\");
         }
         j++;
        }

        TempPath[j] = '\0';
//
// TempPath[] = >>>> "C:\\WORK\\C_Project\\BCB5\\testADO\\Data\\cat22.mdb";
//
      ConnectionString=  "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security
Info=False;Data Source=";
      ConnectionString += AnsiString(TempPath);
//
        DM->ADOConnection->ConnectionString = ConnectionString;
//
        if(GetFileAttributes(TempPath) == 0xFFFFFFFF)
        {
          Application->MessageBox(
        "File not exist !",
        TempPath,
        MB_OK+MB_SYSTEMMODAL);
        }
         else
         {
                Application->MessageBox(
        "OK - try to connect...",
        TempPath,
        MB_OK+MB_SYSTEMMODAL);

//
// try to connect  (file exist !!!)
//
        DM->ADOConnection->Open("Admin", "");
//
        DM->CATADOTable->Connection = DM->ADOConnection;
        DM->CATADOTable->Open();
        DM->RISADOTable->Connection = DM->ADOConnection;
        DM->RISADOTable->Open();
        DM->DETADOTable->Connection = DM->ADOConnection;
        DM->DETADOTable->Open();
        DM->SEDADOTable->Connection = DM->ADOConnection;
        DM->SEDADOTable->Open();
        DM->UZLADOTable->Connection = DM->ADOConnection;
        DM->UZLADOTable->Open();
    }
     catch(EOleException &E)
     {
      Application->MessageBox(
      "��������� �������������� �������� ��� ���������� � ����� ������ !",
      "����������� ������",
      MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL);
     }
}

What`s wrong in VARIANT 2?

Slava
Technical Details
Message-ID: <3c99c030_1@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!207.217.77.43.MISMATCH!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsfeed0.news.atl.earthlink.net!news.atl.earthlink.net!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,cf9389e373692e47,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2002-03-21 03:31:33 PST
From: "Slava Sh." <slava@space.com>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Sample : connect to database Access - what`s wrong this code?
Date: Thu, 21 Mar 2002 14:12:55 +0300
Lines: 167
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 195.161.129.83
Message-ID: <3c99c030_1@dnews>
X-Trace: dnews 1016709168 195.161.129.83 (21 Mar 2002 03:12:48 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!207.217.77.43.MISMATCH!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsfeed0.news.atl.earthlink.net!news.atl.earthlink.net!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews