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.
Sparky
FMTEYEWTK
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.