#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    47
    Rep Power
    11

    Creating an ODBC Link


    In Delphi how do i go about programatically create an ODBC Link for MS Access??

    is it possible??
    how reliable is it, with different versions of windows and sercurity settings????
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,641
    Rep Power
    4247
    1. Create a unit called ODBC.pas and add the following into the file:
    Code:
    unit ODBC;
    
    interface
    
    uses 
        Windows;
    
    Const
       ODBC_ADD_DSN=1;
       ODBC_CONFIG_DSN=2;
       ODBC_REMOVE_DSN=3;
       ODBC_ADD_SYS_DSN=4;
       ODBC_CONFIG_SYS_DSN=5;
       ODBC_REMOVE_SYS_DSN=6;
       ODBC_REMOVE_DEFAULT_DSN=7;
    
    function SQLConfigDataSource(HwndParent:HWND;FRequest:WORD;Driver:PChar;
                                       Attributes:Pchar):boolean;Stdcall;
    function SQLGetInstalledDrivers(Size:String;Buff:WORD;BuffOut:WORD):boolean;Stdcall;
    
    implementation
    
    function  SQLConfigDataSource;external 'odbccp32.dll' name 'SQLConfigDataSource';
    function SQLGetInstalledDrivers;external 'odbccp32.dll' name 'SQLGetInstalledDrivers';
    end.
    2. In your program, put ODBC in your uses clause.
    3. To add the datasource, do something like this:
    Code:
    SqlConfigDataSource(Handle, ODBC_ADD_DSN,Name of ODBC driver, Driver Parameters ending with NULL character);
    
    For example:
    SqlConfigDataSource(0, ODBC_ADD_DSN, 'Microsoft Access Driver (*.mdb)', 'DSN=somename\0 Database=c:/path/to/file.mdb\0 uid=username\0 pwd=somepassword\0');
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    47
    Rep Power
    11
    ok thanks ill give it go

IMN logo majestic logo threadwatch logo seochat tools logo