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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl and SQL Server 2

Status
Not open for further replies.

WxJ

Technical User
Jun 8, 2006
5
0
0
US
I'm trying to get perl to connect to my Microsoft SQL Server, but have no idea what the host needs to be. I've tried localhost, I've tried the name of the server, nothing so far has worked. Help!
 
are you using a DSN? what connection string are you using

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Check out the details in your ODBC control applet the information should be stored there ...

HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
You need to set up a DSN (I usually use a 'system' one). Control panel->Administrative Tools->Data Sources(ODBC)->Add and just follow the wizard.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Once you have a system DSN setup, you can access the server this way:
Code:
my $dsn = 'DBI:ODBC:XXX'; # XXX is the name of the DSN you created
my $user = 'user'; # valid username that can access the DB
my $auth = 'pass'; # valid password
my($dbh) = DBI->connect($dsn,$user,$auth,
							{ RaiseError => 1, AutoCommit => 1});

Then you make your calls to $dbh like normal.

Raklet
 
or if you're not using ODBC and are using one of the TDS/Sybase DBD's, check out pages four and five in this tutorial, the relevant part being:
Code:
[COLOR=#0000FF]use[/color] DBI;
[COLOR=#0000FF]my[/color] $server = [COLOR=#808080]"ibmxp"[/color];
[COLOR=#0000FF]my[/color] $db = [COLOR=#808080]"pubs2"[/color];
[COLOR=#0000FF]my[/color] $username = [COLOR=#808080]"sa"[/color];
[COLOR=#0000FF]my[/color] $password = [COLOR=#808080]""[/color];

[COLOR=#0000FF]my[/color] $dbh = DBI->[COLOR=#FF0000]connect[/color]([COLOR=#808080]"dbi:Sybase:$server"[/color], $username, $password);
$dbh->[COLOR=#0000FF]do[/color]([COLOR=#808080]"use $db"[/color]);

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
Thanks all, I got it working with the ODBC DBD.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top