mhoang has asked for the wisdom of the Perl Monks concerning the following question:

I am seeking opinion for using user or System DSN. Basically i try to write the web based CGi script to connect to sql server 2005 so that user can query database for selected tables. Should i use system or user DSN for that job. Also if using Win32::ODBC::Data Sources() i can only collect all the system DSNs but not user DSN. Can anyone suggest the way to collect both or user DSN only?

Replies are listed 'Best First'.
Re: user and system DSN
by ig (Vicar) on Sep 03, 2009 at 08:31 UTC

    Where possible, I use DSN-less connections to avoid the administrative overhead of setting up and maintaining the DSNs. If you use DSN-less connections, make sure your connection strings can easily be updated (i.e. don't hard code them in many places throughout your code).

    Where DSNs are necessary, I generally use system DSNs but if the application and system are administered by different teams, coordinating changes can be problematic, depending on how well the teams work together.

    I have used Win32::OLE to instantiate an "ADODB.Connection" object with "Provider=sqloledb" in the past. This doesn't require a DSN. If I wanted to use DBI, I would probably investigate DBD::ADO, but I haven't used it thus far. I don't often connect Perl applications to SQL Server.

    You can find and set all the system and user DSNs in the registry. I don't know if there are other interfaces, but I have found direct manipulation of the registry easy enough for SQL Server connections that I have never bothered to find any other way of setting them up programmatically. To find user DSNs for users other than the currently logged on user you will have to search through the HKEY_USERS hive.