I have a user id, password, database name and datasource details. I want to connect with Perl to a MSSQL server. I just used the following snippet, but I am getting an error.
我有用户ID,密码,数据库名称和数据源详细信息。我想用Perl连接到MSSQL服务器。我刚刚使用了以下代码段,但是我收到了错误消息。
#!/usr/bin/perl -w
use strict;
use DBI;
my $data_source = q/dbi:ODBC:192.168.3.137/;
my $user = q/bharani/;
my $password = q/123456/;
# Connect to the data source and get a handle for that connection.
my $dbh = DBI->connect($data_source, $user, $password)
or die "Can't connect to $data_source: $DBI::errstr";
My error is:
我的错误是:
DBI connect('192.168.3.137','bharani',...) failed: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002) at my sqlconnect.pl line 14
Can't connect to dbi:ODBC:192.168.3.137: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002) at mysqlconnect.pl line 14.
The SQL server runs on another system, I am just trying to connect with above details. Please tell me, should I crease DSN in my system, or is anything missing in my program?
SQL服务器在另一个系统上运行,我只是想尝试连接上面的细节。请告诉我,我应该在我的系统中折叠DSN,还是我的程序中缺少任何东西?
1 个解决方案
#1
17
Everything following 'dbi:ODBC:'
in your connection string is passed to the ODBC driver. For MSSQL, try this connection string:
连接字符串中“dbi:ODBC:”后面的所有内容都将传递给ODBC驱动程序。对于MSSQL,请尝试以下连接字符串:
DBI->connect("dbi:ODBC:Driver={SQL Server};Server=192.168.3.137;UID=$user;PWD=$password")
You can find some more alternatives on connectionstrings.com
您可以在connectionstrings.com上找到更多替代方案
#1
17
Everything following 'dbi:ODBC:'
in your connection string is passed to the ODBC driver. For MSSQL, try this connection string:
连接字符串中“dbi:ODBC:”后面的所有内容都将传递给ODBC驱动程序。对于MSSQL,请尝试以下连接字符串:
DBI->connect("dbi:ODBC:Driver={SQL Server};Server=192.168.3.137;UID=$user;PWD=$password")
You can find some more alternatives on connectionstrings.com
您可以在connectionstrings.com上找到更多替代方案