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

Hello, I am trying to connect to a MsSql Database, but I get an error I don't know what to do about... I installed DBI and DBD:ODBC..
#!/usr/bin/perl -w use strict; use DBI; my $dbhost = 'MUCSQL64'; my $dbuser = 'User'; my $dbpass = 'Password'; my $dbname = 'LotTracking'; my $dbh; #Database Handler $dbh = DBI->connect("dbi:ODBC:DSN=$dbname;host=$dbhost", $dbuser, $dbpass, {'RaiseError' => 1});
And then I get the following Error:
DBI connect('DSN=LotTracking;host=MUCSQL64','User',...) failed: [Micro +soft][ODBC Driver Manager] Data source name not found and no default +driver specified (SQL-IM002)(DBD: db_login/SQLConnect err=-1) at H:\w +ork\Tracking System\ODBCTestingUkas.pl line 17
What did I wrong?
Thanks for help

Replies are listed 'Best First'.
Re: Trying to connect to a MsSql Database
by Samy_rio (Vicar) on Oct 26, 2005 at 11:13 UTC

    Hi Streen, Check the available drivers and data_sources in your system using following code.

    use strict; use DBI; my @drivers = DBI->available_drivers(); $" = "\n"; print "@drivers"; foreach my $driver ( @drivers ) { print "Driver: $driver\n"; if ($driver !~ /prox/i) { my @dataSources = DBI->data_sources( $driver ); foreach my $dataSource ( @dataSources ) { print "\tData Source is $dataSource\n"; } print "\n"; } }

    Regards,
    Velusamy R.

Re: Trying to connect to a MsSql Database
by marto (Cardinal) on Oct 26, 2005 at 11:07 UTC
    Hi Streen,

    Try:
    #!/usr/bin/perl -w use strict; use DBI; my $dbhost = 'MUCSQL64'; my $dbuser = 'User'; my $dbpass = 'Password'; my $dbname = 'LotTracking'; my $dbh; #Database Handler my $DSN = 'driver={SQL Server};Server=$dbhost;database=$dbname;uid=$db +user;pwd=$dbpass;'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die $DBI::errstr\n";

    From the DBD::ODBC documentation (where it "says Connect without DSN The ability to connect without a full DSN is introduced in version 0.21.").
    I am sure this has been covered before, a Super Search would have been a good idea.
    Let me know how you get on.

    Martin

    Updated: Fixed typo thanks to arunvelusamy
      ---my $DSN = 'driver={SQL Server};Server=$dbhost;database=$dbhost;uid= +$db +user;pwd=$dbpass;';
      its 'database=$dbname;' and not 'database=$dbhost;'.
Re: Trying to connect to a MsSql Database
by jesuashok (Curate) on Oct 26, 2005 at 11:14 UTC
    Hi,

    You can check these kind of errors before posting it here. Because there are all very familiar errors when you are new to DB connection using DB.

    Please check whethere the Data Source name is available in your pc.

    Please check whethere you have install the driver.

    "Keep pouring your ideas"