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

hi all, I am using this to login to my MSSQL2K server.
my $DSN = "driver={SQL Server};Server=$host;database=$table;UID=$uname +;PWD=$pwd;"; my $dbh=DBI->connect("dbi:ODBC:$DSN") || die "Error: $DBI::errstr";
This works fine, until i try to connect to a remote SQL server. The remote connection error string says "Microsoft\ODBC SQL Server Driver\SQL Server\Login failed for user '<MyDomain>\<MyUserName>'. (SQL-28000). Which indicates to me, that the $DSN string doesn't really make much difference ($uname and $pwd are not <MyDomain> and <MyUserName>). So i replaced the variable with:
my $DSN = "driver={SQL Server};Server=$host;database=$table;";
The results were the same: local login is OK, remote is not. I am running the scripts under my account, which is an ADMIN member on localhost, but is not on the remote machine, which is probbably why it's possible to access the local sql server. Has anyone got any ideas, why the login is not attempted with the varibles supplied in $DSN? I haven't found any other examples, that would use something other than the $DSN string shown here. 10x, Deda.

Replies are listed 'Best First'.
Re: login to MSSQL via DBI::ODBC
by olivierp (Hermit) on Sep 24, 2003 at 14:14 UTC

    I have experienced this on Win32 platforms with ActiveState Perl 5.8.0 when upgrading DBI to 1.3?

    For some reason, DBI is not taking into account the username & password specified in the DSN.

    However, the following works for me:

    my $dbh=DBI->connect("dbi:ODBC:$DSN", $uname, $pwd) || die "Error: $DB +I::errstr";
    HTH
    --
    Olivier