Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > configuring ODBC DSN with a python script

Reply
Thread Tools

configuring ODBC DSN with a python script

 
 
test test
Guest
Posts: n/a
 
      04-02-2004




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_MACH INE,self.dsn_keyname,1)



# except:



self.dsn_reg_key=wreg.CreateKey(wreg.HKEY_LOCAL_MA CHINE,self.dsn_keyname)



# try:



# self.engine_reg_key=wreg.OpenKey(wreg.HKEY_LOCAL_M ACHINE,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_MAC HINE,self.ODBC_keyname,1)



# except:



self.ODBC_reg_key=wreg.CreateKey(wreg.HKEY_LOCAL_M ACHINE,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.drive r_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,"SafeTransaction s",self.safe_transactions)



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



wreg.CloseKey(self.dsn_reg_key)







self.setRegSZ(self.engine_reg_key,"ImplicitCommitS ync",self.implicit_commit_sync)



self.setRegDWORD(self.engine_reg_key,"MaxBufferSiz e",self.max_buffer_size)



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



self.setRegDWORD(self.engine_reg_key,"Threads",sel f.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=us er;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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
RE: configuring ODBC DSN with a python script Robert Brewer Python 0 02-06-2004 05:23 PM
RE: configuring ODBC DSN with a python script Robert Brewer Python 1 02-06-2004 04:40 PM
RE: configuring ODBC DSN with a python script Robert Brewer Python 1 02-05-2004 03:05 PM
configuring ODBC DSN with a python script Jani Yusef Python 4 02-05-2004 02:04 AM



Advertisments