Gossamer Forum
Home : General : Perl Programming :

MSSQL and ODBC connection

Quote Reply
MSSQL and ODBC connection
I'm trying to make an ODBC connection to a MSSQL database and am hoping someone could shed some light.

The MSSQL database "DSAR" exists on NT server "ASSR_IMGDB1"

Apache web server is running on NT server "NT02", MySql and LinksSQL (utilizing MySql) is running on "NT02". There is also an ODBC connection named "OBSERVER" which connects to the database on "ASSR_IMGDB1" on this server. The connection tests okay and a thick client runs on NT02 which utilizes the ODBC connection. (ANSI Nulls, Paddings and Warnings are NOT checked). DBD::ODBC has been installed.

my test connect/disconnect routine is -

sub {
use DBI;
my $dbh = DBI->connect("DBI:ODBC:database=OBSERVER;host=ASSR_IMGDB1", "", "", {'RaiseError' => 1});
$dbh->disconnect;
}

I get the error

DBI->connect(database=OBSERVER;host=ASSR_IMGDB1) failed: [Microsoft][ODBC Driver Manager] Invalid string or buffer length (SQL-S1090)(DBD: db_login/SQLConnect err=-1) at (eval 10) line 3

What am I missing? If I change the database or host names I get a 'datasourse not found' error. I would have thought the host should be "NT02" since this is where the ODBC connection exists.

Any help is appreciated.Earl
Quote Reply
Re: [Super] MSSQL and ODBC connection In reply to
Hi,

Try:

DBI->connect('DBI:ODBC:OBSERVER', 'user', 'pass');

You must setup a system DSN on the web server machine that connects to the MS SQL server. Once that is setup, all you need to do is pass the name of that DSN into dbi->connect. You don't want to pass the hostname, as that information is stored in the dsn.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] MSSQL and ODBC connection In reply to
Smile Thanks Alex, so simple... just dropping the hostname and it works perfectly. -Earl