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

use DBI; use DBD::ODBC; my ( $data_source, $database, $user_id, $password ) = qw( LocalHost tg + sa aaa ); my $conn_string = "driver={SQL Server};server=gz-datebase;database=tg; +uid=sa;pwd=aaa"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr;
following is the error message, i tried the username and password that could successful login in ODBC of win2000 by manaully, i really don't know where was wrong, please give me a hand, thanks.
DBI connect('driver={SQL Server};server=gz-datebase;database=tg;uid=sa +;pwd=aaa il','',...) failed: at C:\DOCUME~1\gzcnc\LOCALS~1\Temp\dir70.tmp\t.pl + line 6 [Microsoft][ODBC SQL Server Driver][SQL Server]user 'GZ-DATEBASE\gzcnc +' login failed B (SQL-28000)(DBD: db_login/SQLConnect err=-1) at C:\DOCUME~1\gzcnc\L +OCALS~1\Te mp\dir70.tmp\t.pl line 6.

edited: Tue Sep 23 22:26:49 2003 by jeffa - removed br tags, added code tags to error output

Replies are listed 'Best First'.
Re: DBD::ODBC question
by NetWallah (Canon) on Sep 23, 2003 at 17:32 UTC
    From http://www.connectionstrings.com/:

    Standard Security:
    "Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"

    Trusted connection:
    "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;"

    Prompt for username and password: (You need to translate VB to perl)
    oConn.Properties("Prompt") = adPromptAlways
    oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;"

Re: DBD::ODBC question
by barbie (Deacon) on Sep 23, 2003 at 17:58 UTC
    my $dsn = 'DBI:' . $dbv->{driver}; $dbh = DBI->connect($dsn, $dbv->{user}, $dbv->{password}, { RaiseError => 1, AutoCommit => 1 });
    The above is the code snippet from my DBI wrapper that handles DBD::ODBC, where the driver relates to the name in your ODBC setup. In my case it's under the System DSN tab, but it could easily be under the User DSN tab, where you enter the data source and database. In this case $dbv->{driver} is set to 'ODBC:TestDB'. It may be that you ODBC setting and the connection string you are passing are conflicting.

    --
    Barbie | Birmingham Perl Mongers | http://birmingham.pm.org/