Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...