Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
499 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (5)


How to check and install MyODBC driverFormat this article printer-friendly!Bookmark function is only available for registered users!
How to check and/or install ODBC driver for MySQL database from Delphi application
Product:
Delphi 6.x (or higher)
Category:
Database-SQL
Skill Level:
Scoring:
Last Update:
11/19/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet MySQL OBDC MyODBC
Times Scored:
3
Visits:
9870
Uploader: Jani Kleindienst
Company:
Reference: N/A
 
Question/Problem/Abstract:
How can I check if MySQL ODBC driver is installed and how can I Install it from my Delphi application
Answer:



Use these two functions to check or install MyODBC driver. Note that you have to provide myodbc.dll file by yourself.
Functions were tested with the MyODBC driver version 2.50 on Win98 and Win2k.

8<--------------------------------------------------------------------


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//  CheckMyODBCDriver                                                         //
//  -----------------                                                         //
//                                                                            //
//  Checks installation of the MyODBC driver                                  //
//                                                                            //
//  Input:                                                                    //
//     (none)                                                                 //
//                                                                            //
//  Result [Byte]:                                                            //
//     0: MySQL driver installed                                              //
//     1: missing registry values                                             //
//     2: missing file myodbc.dll                                             //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
function CheckMyODBCDriver: Byte;
var fReg: tRegistry;
    bDriversValue, bMySQLKey, bMySQLValues: Boolean;
    sDriver, sSetup: String;
begin
   // checking the registry
   try
      fReg := TRegistry.Create;
      fReg.RootKey := HKEY_LOCAL_MACHINE;

      // checking key entry \Software\ODBC\ODBCINST.INI\ODBC Drivers
      fReg.OpenKey( '\Software\ODBC\ODBCINST.INI\ODBC Drivers', True );
      bDriversValue := fReg.ValueExists( 'MySQL' ) and
                       ( fReg.ReadString( 'MySQL' ) = 'Installed' );

      // checking key entry \Software\ODBC\ODBCINST.INI\MySQL
      bMySQLKey := fReg.KeyExists( '\Software\ODBC\ODBCINST.INI\MySQL' );

      // if exists key entry \Software\ODBC\ODBCINST.INI\MySQL
      // check also the values
      if bMySQLKey then begin
         fReg.OpenKey( '\Software\ODBC\ODBCINST.INI\MySQL', True );
         bMySQLValues := fReg.ValueExists( 'APILevel' ) and
                         fReg.ValueExists( 'ConnectFunctions' ) and
                         fReg.ValueExists( 'Driver' ) and
                         fReg.ValueExists( 'DriverODBCVer' ) and
                         fReg.ValueExists( 'FileExtns' ) and
                         fReg.ValueExists( 'FileUsage' ) and
                         fReg.ValueExists( 'Setup' ) and
                         fReg.ValueExists( 'SQLLevel' );

         if bMySQLValues then begin
            sDriver := Trim( fReg.ReadString( 'Driver' ) );
            sSetup  := Trim( fReg.ReadString( 'Setup' ) );
         end;
      end else
         bMySQLValues := False;



      if ( bDriversValue and bMySQLKey and bMySQLValues ) then Result := 0
                                                          else Result := 1;
      fReg.CloseKey;                                                    
      fReg.Free;
   except
      Result := 1;
      fReg.Free;
      Exit;
   end;

   // if registry entries OK => check driver files ...
   if ( Result = 0 ) then begin
      if not ( FileExists( sDriver ) and FileExists( sSetup ) ) then Result := 2;

   end;


end;


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//  InstallMyODBCDriver                                                       //
//  -------------------                                                       //
//                                                                            //
//  Installs MyODBC driver                                                    //
//                                                                            //
//  Input:                                                                    //
//     sDllLocation - location of the file myodbc.dll [String]                //
//                                                                            //
//  Result [Byte]:                                                            //
//    0: MyODBC succesfuly installed                                          //
//    1: file myodbc.dll does not exist                                       //
//    2: error accesing registry                                              //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
function InstallMyODBCDriver( sDllLocation: String ): Byte;
var fReg: tRegistry;
begin
   if not FileExists( sDllLocation ) then begin
      Result := 1;
      Exit;
   end;

   if ( CheckMyODBCDriver = 0 ) then begin
      Result := 0;
   end else begin
      try
         fReg := TRegistry.Create;
         fReg.RootKey := HKEY_LOCAL_MACHINE;
         fReg.OpenKey( '\Software\ODBC\ODBCINST.INI\ODBC Drivers', True );
         fReg.WriteString( 'MySQL', 'Installed' );
         fReg.CloseKey;
         fReg.CreateKey( '\Software\ODBC\ODBCINST.INI\MySQL' );
         fReg.OpenKey( '\Software\ODBC\ODBCINST.INI\MySQL', True );
         fReg.WriteString( 'APILevel', '2' );
         fReg.WriteString( 'ConnectFunctions', 'YYN' );
         fReg.WriteString( 'Driver', sDllLocation );
         fReg.WriteString( 'DriverODBCVer', '02.50' );
         fReg.WriteString( 'FileExtns', '*.txt' );
         fReg.WriteString( 'FileUsage', '0' );
         fReg.WriteString( 'Setup', sDllLocation );
         fReg.WriteString( 'SQLLevel', '1' );
         fReg.CloseKey;
         fReg.Free;
         Result := 0;
      except
         fReg.Free;
         Result := 2;
      end;
   end;
end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
question
    nina (Nov 8 2005 9:40AM)

hi
how i can create a "system dsn" or "User Dsn" in delphi code.
I want that these create  in run time.
thanks
Respond

:-/
    Gankhuyag Dangaasuren (May 14 2002 2:49AM)

Thank you for your respond.
In the directory "c:\Program Files\Common Files\ODBC\Data Sources" contains
some File DSN entry, but there nothing useful, for example ([ODBC] DSN=TEST).
What ever thank you for your respond. Bye.

Respond

Question
    Gankhuyag Dangaasuren (May 8 2002 3:06AM)

Do you know about that, how I can create SQL server ODBC datasource from my Delphi application with specification about what connection ("With Windows NT authentication using the network login ID" or "With SQL Server authentication using a login ID and password entered by the user"), protocol and port will use?

Respond

RE: Question
Jani Kleindienst (May 13 2002 7:58AM)

You should create File DSN entry. It works like the System DSN, but options are stored in the file instead in the Windows registry. Files are usually located in the "c:\Program Files\Common Files\ODBC\Data Sources" directory. I don't know which options are used by the SQL server, but you can always explore then by creating File DSN entries with the ODBC Data Source Administrator.
Respond

Exelent!!!
    Guillermo Patiño Gonzalez (Dec 14 2001 9:36PM)

Thanks for this comment
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. DSpirito
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)