我有一个用户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";
我的错误是:
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.
sql服务器运行在另一个系统上,我只是试图连接上面的细节.请告诉我,我的系统中是否打折DSN,还是在我的程序中丢失?
解决方法
连接字符串中的“dbi:ODBC:”之后的所有内容都将传递给ODBC驱动程序.对于MSsql,请尝试此连接字符串:
DBI->connect("dbi:ODBC:Driver={sql Server};Server=192.168.3.137;UID=$user;PWD=$password")
你可以在connectionstrings.com找到更多的替代品