Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

linux - Perl connection with mssql server

I'm new to Perl. I'm trying to connect to MSSQL 2016 from Perl. Below is the code I have written and it is working fine in my personal account .

Where as in my organization account MS-MSQL server is running in different machine and I want to connect to it .

Note: running this in Linux machine

#!/usr/bin/perl -w
use strict;

use DBI;

my $user = 'SA';
my $password = '';


my $dbh = DBI->connect('dbi:ODBC:Driver={/opt/microsoft....};Server=localhost;Database=testsb;UID=$user;PWD=$password')
    or die "Can't connect ";

My question is where will I get this driver path since server is running in different machine. Please help ..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't change the path to the driver. That path is local to the machine where your Perl script is running. It's the SQL Server that's remote, so you need to change the Server=localhost section to use the hostname (or better, FQDN) to the remote server.

Also, maybe it's a Linux thing, but in Windows I just have to specify the driver like DBI:ODBC:Driver={SQL Server}, so there's no path involved at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...