configuring ODBC DSN with a python script

Discussion in 'Python' started by test test, Apr 2, 2004.

  1. test test

    test test Guest

    Hello Python user,



    I've read your mail and analysed the problem. The testing i've done was with windows xp pro.



    First thin i have seen, was that you tried to open an existing registry key with wreg.OpenKey. You must only open only a key with with this command i've you want to read the key, i've you want to write to the key always use wreg.CreateKey.



    Below here you will find the most part of youre send code. The code in red is new code, en de code in bleu is changed code.



    Hope you can use this code.



    Sincerly,



    C.R. Groenveld



    The Netherlands



     



     



    #import mx.ODBC.Windows



    import _winreg as wreg



    class access_interface:



    def __init__(self):



    self.dsn_name="test2"



    self.dbq="C:\\prog\\ontwikkel\\test\\db1.mdb"



    self.driver_path="C:\\WINDOWS\\System32\\odbcjt32.dll"



    self.driver_id=25



    self.fil="MS Access;"



    self.safe_transactions=0



    self.uid=""







    self.implicit_commit_sync=""



    self.max_buffer_size=2048



    self.page_timeout=5



    self.threads=3



    self.user_commit_sync="Yes"







    self.dsn_reg_key=None



    self.dsn_keyname="Software\\ODBC\\ODBC.INI\\%s" %(self.dsn_name)







    self.engine_reg_key=None



    self.engine_keyname="Software\\ODBC\\ODBC.INI\\%s\\Engines\\Jet" %(self.dsn_name)







    self.ODBC_reg_key=None



    self.ODBC_keyname="Software\\ODBC\\ODBC.INI\\ODBC Data Sources"



    print self.ODBC_keyname







    def createDSN(self):



    # try:



    # self.dsn_reg_key=wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE,self.dsn_keyname,1)



    # except:



    self.dsn_reg_key=wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE,self.dsn_keyname)



    # try:



    # self.engine_reg_key=wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE,self.engine_keyname,1)



    # except:



    self.engine_reg_key=wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE,self.engine_keyname)



    # try:



    # self.ODBC_reg_key=wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE,self.ODBC_keyname,1)



    # except:



    self.ODBC_reg_key=wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE,self.ODBC_keyname)







    if self.dsn_reg_key!=None and self.engine_reg_key!=None and self.ODBC_reg_key!=None:



    self.setRegSZ(self.dsn_reg_key,"DBQ",self.dbq)



    self.setRegSZ(self.dsn_reg_key,"Driver",self.driver_path)



    self.setRegDWORD(self.dsn_reg_key,"DriverId",self.driver_id)



    self.setRegSZ(self.dsn_reg_key,"FIL",self.fil)



    self.setRegDWORD(self.dsn_reg_key,"SafeTransactions",self.safe_transactions)



    self.setRegSZ(self.dsn_reg_key,"UID",self.uid)



    wreg.CloseKey(self.dsn_reg_key)







    self.setRegSZ(self.engine_reg_key,"ImplicitCommitSync",self.implicit_commit_sync)



    self.setRegDWORD(self.engine_reg_key,"MaxBufferSize",self.max_buffer_size)



    self.setRegDWORD(self.engine_reg_key,"PageTimeout",self.page_timeout)



    self.setRegDWORD(self.engine_reg_key,"Threads",self.threads)



    self.setRegSZ(self.engine_reg_key,"UserCommitSync",self.user_commit_sync)



    wreg.CloseKey(self.engine_reg_key)



    self.setRegSZ(self.ODBC_reg_key,self.dsn_name, "Microsoft Access Driver (*.mdb)")



    wreg.CloseKey(self.ODBC_reg_key)







    def setRegSZ(self,reg_key,reg_name,reg_value):



    print reg_key



    print reg_name



    print reg_value



    wreg.SetValueEx(reg_key,reg_name,0,wreg.REG_SZ,reg_value)







    def setRegDWORD(self,reg_key,reg_name,reg_value):



    wreg.SetValueEx(reg_key,reg_name,0,wreg.REG_DWORD,reg_value)







    def getCursor(self):



    db=mx.ODBC.Windows.DriverConnect('DSN=test2;UID=user;PWD=passwd')



    c=db.cursor()



    return c







    def getRows(self):



    c=self.getCursor()



    c.execute('select * from puke')



    mx.ODBC.print_resultset(c)







    if __name__=="__main__":



    ai=access_interface()



    ai.createDSN()



    ai.getRows()




    Ontvang je Hotmail & Messenger berichten op je mobiele telefoon met Hotmail SMS klik hier
    test test, Apr 2, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jani Yusef
    Replies:
    4
    Views:
    492
    Jean-Yves Vinet
    Feb 5, 2004
  2. Robert Brewer
    Replies:
    1
    Views:
    616
    omission9
    Feb 5, 2004
  3. Robert Brewer
    Replies:
    1
    Views:
    385
    omission9
    Feb 6, 2004
  4. Robert Brewer
    Replies:
    0
    Views:
    357
    Robert Brewer
    Feb 6, 2004
  5. Arpan

    System DSN Faster Than File DSN!

    Arpan, Jun 26, 2005, in forum: ASP General
    Replies:
    7
    Views:
    253
Loading...

Share This Page