0

初めて接続をテストしようとしています。このように

#!/usr/bin/perl -w
use DBI;
# DBD::ODBC
use CGI::Carp qw(fatalsToBrowser);
my $dsn = 'DBI:ODBC:Driver={SQL Server}';
#my $host = 'localhost';
my $host = 'mysql';
my $database = 'test';
my $user = 'root';
my $auth = 'mukesh';
# Connect via DBD::ODBC by specifying the DSN dynamically.
my $dbh = DBI->connect("$dsn;Server=$host;Database=$database",$user,$auth) || die "Database connection not made: $DBI::errstr"; 

しかし、私はこのエラーを何度も繰り返しています。 Got error [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (SQL-08001) [state was 08001 now 01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (SQL-01000) when connecting to

これを行う前に、PC で設定する必要があるものはありますか。

4

2 に答える 2

3

You seem to be using a Microsoft SQL server connection to a MySQL database - that isn't going to work.

You possibly want something like;

my $dsn = "DBI:mysql:database=$database;host=$host;port=3306";
my $dbh = DBI->connect($dsn, $user, $auth) || die "Database connection not made: $DBI::errstr"; 

But you also seem to be confused about the host - are you sure the host name for the mysql database is 'mysql'? If it's running on the same machine, localhost would be correct.

I also hope those aren't your real root credentials - perhaps posting those in a public forum isn't a great idea, but also connecting as root is almost certainly not what you want to do, consider using a specific user with only the required permissions.

于 2013-09-15T11:54:24.753 に答える