[DB-SIG] DSN or not

M.-A. Lemburg mal at egenix.com
Wed Oct 24 15:54:00 CEST 2007


Carl Karsten wrote:
>>> An example from my code, which returns a database connection:
>>>
>>> import pyodbc
>>>
>>> def connect_to_db2():
>>>     """
>>>     quick and dirty connect to db2
>>>     """
>>>     s='DRIVER={iSeries access ODBC Driver};SYSTEM=10.3.36.150;UID=%s;PWD=%s'
>>>     return
>>> connect_to_db(connect_str=s%('myuser','mypassword'),autocommit=True)
>>>
>>> db=connect_to_db2()
>>> c=db.cursor()
>>> #
>>> # insert working code here
>>> #
>>> c.close()
>>> db.close()
>>>
>> You will also want to define a system data source on the machine
>> your running the above code on, instead of passing the driver
>> details to the Windows ODBC Manager directly. This makes your
>> code both more portable and creates fewer issues with Windows
>> permission management.
> 
> I disagree with the "DSN is best" generalization.  They both have their places, 
> and it is up to the developer to chose which is best for a given situation.  In 
> the case of sample code being posted to a mail list, I think DSNs just confuse 
> things, as where a DSNless connection string makes it clear exactly what options 
> are being set.
> 
> I will agree that for production code, DSNs have something to offer, but even 
> then there are cases where they aren't needed.

I'm happy to agree that we disagree :-)

Data source details are part of the system configuration and
as such shouldn't be part of application code.

Even if you post code as example, the developer will have to install
the ODBC driver and it's usually easier to setup a data source using
the GUI tools available for the drivers right along with it,
than trying to find the right option syntax for the DSN keywords.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 24 2007)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611


More information about the DB-SIG mailing list