Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

DBD::ODBC, FreeTDS and Stored Procedure

by InfiniteLoop (Hermit)
on Sep 28, 2006 at 20:11 UTC ( #575419=perlquestion: print w/replies, xml ) Need Help??

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

Greetings Monks,
 I have installed DBD::ODBC and have setup FreeTDS driver, via unixodbc, to connect to a MS SQL server. Here is my simple test code to execute a stored procedure:
use DBI; my $DSN = 'driver=FreeTDS;Server=mssql_server; database=test;uid=user; +pwd=password;'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n"; my $sth = $dbh->prepare('EXEC sp_who'); $sth->execute();
While executing this code, I get the error:
 DBD::ODBC::st execute failed: (DBD: st_execute/SQLExecute err=-1)
I have searched the monastory and found a few questions, such as MS SQL Stored Procedure Syntax, however there didn't seem to be any conclusive answers.

How do I execute stored procedure against a MS SQl server, using DBD::ODBC ? Although Im not able to execute a stored procedure, other SQL queries work. Thanks.

Replies are listed 'Best First'.
Re: DBD::ODBC, FreeTDS and Stored Procedure
by imp (Priest) on Sep 28, 2006 at 20:36 UTC
    The syntax for the stored procedure call is fine, so your problem is elsewhere.

    I haven't looked at unixodbc for about 5 years, but I have used iodbc with freetds to talk to a mssql in the past year with no problems.

    If that is an option for you, the installation instructions I provided in this node might be useful.

Re: DBD::ODBC, FreeTDS and Stored Procedure
by mje (Curate) on Sep 29, 2006 at 10:31 UTC
    If you ran make test when you built DBD::ODBC and were connecting to MS SQL Server, the test 20SqlServer should have been run and that includes calls to procedures (look in t/20SqlServer in the DBD::ODBC distribution).

    There should have been more to the error message than you have provided.

    The proper ODBC syntax is { call sp_who() }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://575419]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2020-06-01 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (177 votes). Check out past polls.

    Notices?