Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

DBD::ODBC Connecting without DSN from Win32

by sparkyichi (Deacon)
on Jul 25, 2002 at 21:11 UTC ( #185344=perlmeditation: print w/replies, xml ) Need Help??

This is not a question but more of general information that I thought might be useful to some people. I had looked all over for this information and could not find it or it might have been that I just didn't know where to look.

I am trying to execute SQL queries from a Win32 workstation or web server. I did not want to create a ODBC DNS entry and for portability reason I did not want to use WIN32::ODBC. There is an example in the DBD::ODBC pod for MSSQL that is close to what you want. This node is also helpful.

The first thing you want to do is find the MS driver that you will have to use. You can find this by going to you control panel -- Data Sources In the drivers tab. You will find information you looking for in the name column. In my case it was "Microsoft ODBC for Oracle." This is the driver you will want to use such as the example in DBD::ODBC, "SQL Server." You can then complete out the rest of the example with your information: server name, user name and password with the exception of "database." I could not find anything to put there that did not cause the following error:
Microsoft ODBC Driver Manager Invalid string or buffer length (SQL-S1090)(DBD: db_login/SQLConnect err=-1)
By luck I found out that you do not need to use this, at least when you are connecting to Oracle.

I hope that this will be able to help some people out.
#!c:/perl/bin/perl -w use DBI; use strict; my $stmnt = "select * from Some_Table where day > \'01 Apr 2002\'"; my $DSN = 'driver={Microsoft ODBC for Oracle}; Server=Oracle_Server_Name; uid=user;pwd=password;'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n"; my $sth = $dbh->prepare($stmnt); $sth->execute; while (@row_ary = $sth->fetchrow_array()){ print "@row_ary\n"; } $dbh->disconnect;

Update: Fixed minor error.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://185344]
Approved by Aristotle
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-05-23 17:31 GMT
Find Nodes?
    Voting Booth?