Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mssql

Status
Not open for further replies.

kevin197

Programmer
Mar 21, 2002
88
GB
How do I connect to a mssql database running on a windows machine from perl running on a unix machine?

I use

$dbh = DBI->connect('DBI:mysql:database', "$mysqlusername", "$mysqlpassword"),{RaiseError => 1};

for mysql

I'm getting confused with everything I've been reading on the net about it. Isn't there just a simple way like

$dbh = DBI->connect('DBI:mssql:database', "$mysqlusername", "$mysqlpassword"),{RaiseError => 1};

?
 
Try using Win32::ODBC and just point to the ODBC source

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
If I just did this would it work?

And can I just replace JDBC with the windows server ip running mssql?


#!/usr/bin/perl
#
use DBI;

my $dbh = DBI->connect("dbi:Sybase:server=JDBC", 'guest', 'sybase', {PrintError => 0});

die "Unable for connect to server $DBI::errstr"
unless $dbh;

my $rc;
my $sth;

$sth = $dbh->prepare("select \@\@servername");
if($sth->execute) {
while(@dat = $sth->fetchrow) {
print "@dat\n";
}
}
 
I'd guess it would depend on the version of SQL server, SQL Server was bought off Sybase as version SQL Server 6.5, I *think*, but whether that's still valid as of 2008, I'd doubt as they claim that 2008 is a complete rewrite.

Apologies, shouldn't scan posts like that, didn't even see the Unix qualification. You'll need the MSSQL DBD (Database Driver) more from here

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks for your help. I've read that many different things on the net but I'm sure a lot of it is out of date.

The database I need to connect to is mssql 2005

The server I'm connecting from is centos running cpanel and perl.

What I really need is a bit of code from someone who has done this before. I only really read to do basic reading and updating of the mssql database, no limit commands or anything.

DBI and DBD::ODBC look like the way to go.

Does this look right?

dbi:mSQL:hostname:database:port_number
 
use DBI;

$dbh = DBI->connect('dbi:ODBC:DSName', 'user', 'password');

mSQL afaik is/was a MySQL variant

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top