Connecting With Perl Using Win32 : ODBC

  • Comments posted to this topic are about the content posted at

    K. Brian Kelley

  • I enjoyed your article very much. Can you tell me the name of the book you mention which is "out for those researchers in the biological sciences who want to use Perl to help process some of their data." Thanks.

  • Sure. The book is called Beginning Perl for Bioinformatics and its available from O'Reilly. Here's the O'Reilly page on it:

    The first sentence of the description reads:


    This book shows biologists with little or no programming experience how to use Perl, the ideal language for biological data analysis.

    K. Brian Kelley

  • great article it gives me a good start on using perl. I have one question is it also posible to create a dsn less connection. This makes it easier to move the script to an other server. maybe for pearl this is less needed because perl is more a server then a client language.

  • Yes. The next couple of articles should talk about doing just that.

    Most of the scripts I have written where I work use Win32:LE which gives me access to standard COM objects like ADO. Since, from a supportability perspective most of the developers are familiar with ADO even if they're not familiar with Perl, I've used Win32:LE and ADO to make database connections, although DBI is more "Perl." In those cases I specify a standard ADO ConnectionString, to include specifying provider, server, initial catalog, etc.

    I'll be focusing on using Win32:LE and ADO in my next article in the series.

    K. Brian Kelley

  • Hi,

    I dont know anything about PERL when I was reading your article. It has given very good idea about PERL, thanks for writting this article. Could U suggest a good book that covers all info about PERL. I would greatful to U.





  • I have a Getting Started page on Perl. I've also listed some of the books you'll want to look at to get started. The Learning Perl in Win32 Systems is where you should start in the literature.

    K. Brian Kelley

  • I couldn't thank you more !

    I am new to Perl-ODBC and this article really get me started !

    Thank you once again.

  • Well written article and an interesting read, I still don't see what advantage I might gain from it however, and as far as users are concerned the last thing I'd ever want is any form of ad-hoc query or access to database tables.

    That said I only use SQL Server, it's years since I was using unix, so maybe for a windows only person like me it has less value and has more value working in multiple platforms.

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]

  • With respect to scripting languages on the Windows platform, Perl gives a person more options than VBScript and JScript (even with WScript). For administrators and DBAs, there's a lot of flexibility with going with Perl. As for ad hoc access, I agree, this doesn't tend to be something we allow the normal person to do. However, when we want a quick script to pull something out of a database or insert some info, we may not go through the trouble of building out the full security model because the risk is relatively small.

    Also, Win32-ODBC (replaced the :: with a - to avoid the smily) is kind of the "entry point" into database access with Perl. There are better options available, I just haven't gotten around to writing about them. One example is the following from SQL Server MVP Erland Sommarskog:


    Also, check out the book Real World SQL Server Administration with Perl

    SQL Server MVP Linchi Shea gives a whole book of uses for Perl with SQL Server.

    K. Brian Kelley

  • Great article, very comprehensive.

    However I have found there are memory leaks with the Win32:DBC module.

    After spending a great deal of time trying checking my code for objects/variables not destoyed in subs I ended up using Perl DBI.

    I have found this very useful and would recommend others trying this module to see which they prefer.

  • Perl is very much for the administrator and developer and not for the end user.  It has a prominent place in the toolbox, but it's not for end users.

    My one criticism of the article is, as with most SQL Server script examples, it has a password hard coded in, in plain text.  No wonder the young folk all think that's perfectly acceptable!   DBAs kill themselves setting up least privelege and "useless by default", and then here are these plain text passwords in the code - or worse, on the command line!

    Aside from that, let me mention DBI:Sybase (and perhaps, Sybperl). 

    If you are connecting from a non-Windows box, the Win32 module won't do you a bit of good.  Or, if you come from a database background instead of a Windows background, you might be more comfortable with db-lib than ODBC.  In that case, the DBI:Sybase modules are the way to go.

    The trick is to compile with the FreeTDS libraries instead of the Microsoft or the Sybase libraries, and you can talk to anything that uses a TDS stream from a single binary.

    Roger Reid

    Roger L Reid

  • Keep in mind, though, that in writing articles, you focus on the technology that the article is primarily about. While I agree with you about securing the connection string, the truth of it is that with respect to this article it's a rabbit trail. Explaining why it's an issue and various ways to secure the connection string would double the length of the present article, if not more. In the mean time, the focus on using Perl to connect to SQL Server is lost.

    K. Brian Kelley

  • Brian,

    Thanks for article. I am a complete Perl newbie and was able to take the samples and article content and successfully query data from my legacy ERP system in about 10 minutes. Thanks very much. Looking forward to your upcoming articles.

    Josh Blair

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply