creating an odbc link with python

Niki Spahiev spahievi at vega.bg
Sat Dec 9 14:23:47 EST 2000


08.12.2000, 02:23:40, Scott Hathaway wrote:

SH> Hello Everyone,

SH> I am using python to create an installation program for a web app that we
SH> have at our company.  The web app uses an access database that is hooked up
SH> through odbc.  How can I programatically create the dsn in python (I guess I
SH> need to edit the windows registry)?

SH> Thanks,
SH> Scott

Something like that:

def ConfigDSN( dsn ): #FOLD00
    from odbc_installer import config_data_source, ODBC_ADD_SYS_DSN
    import w32reg

    try:
        ho = w32reg.OpenKey( w32reg.HKEY_LOCAL_MACHINE, 'Software\\ODBC\\ODBC.INI\\' + dsn )
    except RuntimeError:
        path = os.path.abspath( 'Trz.db' )
        print 'DataSource', dsn, path
        config_data_source( ODBC_ADD_SYS_DSN, "Sybase SQL Anywhere 5.0", join( [
          "DSN=" + dsn,
          "Database=" + path,
          "DatabaseFile=" + path,
          "DatabaseName=TRZ_DB",
          "\0"], "\0" )
        )
        ho = w32reg.OpenKey( w32reg.HKEY_LOCAL_MACHINE, 'Software\\ODBC\\ODBC.INI\\' + dsn )
    try:
        try:
            w32reg.ReadKeyVal( ho, 'Start' )
        except RuntimeError:
            driver = w32reg.ReadKeyVal( ho, 'Driver' )
            path = os.path.dirname( driver )
            start = os.path.join( path, 'rtdsk50.exe' )
            print 'Start', start
            w32reg.WriteKeyVal( ho, 'Start', start )
    finally:
        w32reg.CloseKey( ho )


-- 
Best regards,
 Niki Spahiev






More information about the Python-list mailing list