如何将Perl连接到SQL Server? [英] How do I connect with Perl to SQL Server?

查看:135
本文介绍了如何将Perl连接到SQL Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户ID,密码,数据库名称和数据源详细信息。我想将Perl连接到MSSQL服务器。我只是使用以下代码段,但出现错误。

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.

#!/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 Server在另一个系统上运行,我只是尝试连接上述详细信息。请告诉我,是否应该在系统中创建DSN,或者程序中缺少任何内容?

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?

推荐答案

<$ c之后的所有内容连接字符串中的$ c>'dbi:ODBC:'传递给ODBC驱动程序。对于MSSQL,请尝试以下连接字符串:

Everything following 'dbi:ODBC:' in your connection string is passed to the ODBC driver. For MSSQL, try this connection string:

DBI->connect("dbi:ODBC:Driver={SQL Server};Server=192.168.3.137;UID=$user;PWD=$password")

您可以找到一些 connectionstrings.com

这篇关于如何将Perl连接到SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆