Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Connecting to a MS SQL 2k Server

by Eagle_f90 (Acolyte)
on Jul 24, 2003 at 21:24 UTC ( [id://277696]=perlquestion: print w/replies, xml ) Need Help??

Eagle_f90 has asked for the wisdom of the Perl Monks concerning the following question:

I need to connect to a MS SQL 2k Server with out using the DBD::ODBC module useing perl. Can someone please help?

Replies are listed 'Best First'.
Re: Connecting to a MS SQL 2k Server
by princepawn (Parson) on Jul 24, 2003 at 23:38 UTC
    There are plenty of non DBD::ODBC options here

    Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

      I'll just add to Erland's document that you refer to that FreeTDS is usually used in conjunction with DBD::Sybase (or DBD::ODBC) to connect to MS-SQL servers.


        Since we are on this thread, perhaps I should mention that I have been struggling to connect to MS SQL via DBD::Sybase for the last two days. Connection to Sybase/Linux via DBD::Sybase is just fine, but connecting to MS SQL 2000 leads to problems
        use DBI; my $data_source = "dbi:Sybase:database=SynergyOne;server=MSSQL"; my $username = 'sa'; my $auth = ''; + + my $dbh = DBI->connect($data_source, $username, $auth) or die "no connection: $DBI::errstr";
        [tbone@MDB tbone]$ ~/bin/ DBI connect('database=SynergyOne;server=MSSQL','sa',...) failed: at / +home/tbone/bi\ n/ line 9 no connection: OpenClient message: LAYER = (1) ORIGIN = (2) SEVERITY = + (6) NUMBER = (151) Message String: ct_connect(): user api layer: internal Client Library +error: A connection to the server must exist on the connection struct +ure before this routine can be called. [tbone@MDB tbone]$

        Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Re: Connecting to a MS SQL 2k Server
by MrCromeDome (Deacon) on Jul 24, 2003 at 21:36 UTC
    What's wrong with DBD::ODBC? Not installed? Can't install? Want Win32::ODBC for some reason? What OS is your Perl script running on? Linux? Win32?

    Throw me a bone here! ;) I can't help without more info.


      Sorry, was not thinking before submitting that info.
      There is nothing wrong with it. This is for a message board that connects to the database of a user's chocice for it's backend. So some people don't have ODBC installed, some can't get it installed, other just don't want to install it. The perl script will be runing on all differant OSes but mainly windows and *nix. I have already created a script to connect using ADO and ODBC, just don't know how to make one that just does not use either one of thouse.
        To communicate with a database, you have to have a client that speaks that database's language. The various DBD:: modules communicate with those clients. The model looks something like:
        Perl code <-> DBI <-> DBD:: <-> Database client <-> Database
        In other words, if they want to connect to database XYZ, they have to have the client for XYZ installed and the appropriate DBD::. Then, you have to support XYZ's connection string.

        Those connection strings do differ between databases, as do the files necessary to support them. For example, DBD::Sybase (which is used to connect from Unix to SQL Server) can use freetds, which uses a file called freetds.conf. However, DBD::Oracle uses an oracle client which requires (usually) a file called tns.ora. It's not as simple as installing the right DBD:: module.

        In other words ... either you have to control the database choices on your server or you have to provide a mechanism for people who install your stuff to be able to connect to their DB of choice. Good luck! :-)

        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        This sounds. . . interesting ;)

        Is this a CGI app or a client/server app? If CGI, I take it this app is installed multiple times in multiple places? I'm just wondering why you need to have the different code. By using DBI, you can make it easy to switch between various databases and not have to change any code. Behold my untested (simple) example:

        if($dbms eq "mysql") { $driver = "mysql"; $db = "test"; $user = "root"; $pw = ""; } elsif($dbms eq "mssql" { $driver = "ODBC"; $db = "test"; $user = "sa"; $pw = ""; } my $dbh = DBI->connect("DBI:$driver:$db", $user, $pw, { RaiseError => 1});
        If you don't want to use ODBC, you might consider using DBD::Sybase. Haven't tried it, but SQL Server is derived from Sybase, so you might have some luck there.

        Is this what you're looking for, or am I completely misunderstanding?


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://277696]
Approved by MrCromeDome
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 16:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found