odbc link from python

Scott Hathaway slhath at home.com
Tue Dec 12 04:43:05 CET 2000


I asked how to create an odbc link from python a couple of days ago.  Thanks
to help from Alex Martelli, I have solved my problem.  If anyone else is
interested, here is the code below.

Since I am just beginning with python, I am sure that vast improvements can
be made.  This code adds a MS Access System dsn named "tri2".

import _winreg as w

parentKey =
w.OpenKey(w.HKEY_LOCAL_MACHINE,r'Software\ODBC\ODBC.INI',0,w.KEY_WRITE)
newKey = w.CreateKey(parentKey,'tri2')
w.SetValueEx(newKey,'DBQ',0,w.REG_SZ,r'c:\apache\htdocs\t2\mdb\Trinity.mdb')
w.SetValueEx(newKey,'Driver',0,w.REG_SZ,r'c:\windows\system\odbcjt32.dll')
w.SetValueEx(newKey,'DriverId',0,w.REG_DWORD,25)
w.SetValueEx(newKey,'FIL',0,w.REG_SZ,'MS Access;')
w.SetValueEx(newKey,'SafeTransactions',0,w.REG_DWORD,0)
w.SetValueEx(newKey,'UID',0,w.REG_SZ,'')

parentKey =
w.OpenKey(w.HKEY_LOCAL_MACHINE,r'Software\ODBC\ODBC.INI\tri2',0,w.KEY_WRITE)
newKey = w.CreateKey(parentKey,'Engines')

parentKey =
w.OpenKey(w.HKEY_LOCAL_MACHINE,r'Software\ODBC\ODBC.INI\tri2\Engines',0,w.KE
Y_WRITE)
newKey = w.CreateKey(parentKey,'Jet')
w.SetValueEx(newKey,'ImplicitCommitSync',0,w.REG_SZ,'')
w.SetValueEx(newKey,'MaxBufferSize',0,w.REG_DWORD,2048)
w.SetValueEx(newKey,'PageTimeout',0,w.REG_DWORD,5)
w.SetValueEx(newKey,'Threads',0,w.REG_DWORD,3)
w.SetValueEx(newKey,'UserCommitSync',0,w.REG_SZ,'Yes')

parentKey = w.OpenKey(w.HKEY_LOCAL_MACHINE,r'Software\ODBC\ODBC.INI\ODBC
Data Sources',0,w.KEY_WRITE)
w.SetValueEx(parentKey,'tri2',0,w.REG_SZ,'Microsoft Access Driver (*.mdb)')

Hope this helps someone else!

Scott





More information about the Python-list mailing list