Thanks for your help, but I got it working a different way - using DBI.
For anyone who's interested - it seems difficult to find info on accessing MS SQL Server from Perl. I used DBI and DBD::ODBC - I was able to get a connection going with Win32::ODBC and RDBAL but wasn't sure about running stored procedures with these methods.
Here's the code...note you need to install DBI, DBD::ODBC and set up a system DNS to connect to database from your ODBC data sources control panel - there may be a way to get a DSN-less connection though. Also, you must initialise any parameter being bound to a placeholder and used as an output parameter to the stored procedure to some valid value of the expected datatype. If you're expecting a string then initalise to ' ' or other string value. If you're getting some datatype conversion error ("error converting data type ... to ..."), then this could be the problem.
use DBI;
use DBI qw(:sql_types);
my $MSSQL_uid = 'myuid';
my $MSSQL_pwd = 'mypwd';
my $MSSQL_svr = 'mysqlsvr';
my $MSSQL_db = 'mydb';
my $MSSQL_dsn = "dbi:ODBC:$MSSQL_db";
my $sth; # statement handle
# connect to DB
my $dbh = DBI->connect($MSSQL_dsn, $MSSQL_uid, $MSSQL_pwd)
or die "Couldn't connect to $MSSQL_svr : $DBI::errstr\n";
print "\n\nConnected to $MSSQL_dsn DS\n\n";
# execute stored procedures and get output parameter value
my $param1_int = 0; # note you must initalise this to something
my $exe_string = "EXECUTE my_stored_procedure" .
"?, " .
"'$param2_str', " .
"'$param3_str', " .
"$param4_int";
$sth = $dbh->prepare($exe_string)
or die "\nCouldn't prepare statement : $DBI::errstr\n";
$sth->bind_param_inout(1, \$param1_int, 50)
or die "\nCouldn't bind param inout : $DBI::errstr\n";
$sth->execute
or die "\nCouldn't execute stored procedure : $DBI::errstr\n";
print "Output parameter value is now $param1_int\n";
# disconnect from DB
$dbh->disconnect
or die "\nError disconnecting : $DBI::errstr\n";
Andrew
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.