Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Unanswered: Problems connecting to SQL Server DB using Perl CGI

    Please help. I am at my wits end.

    I have SQL Server 2000 on a Windows 2003 server. I have my database on a Nmade Instance . Named Pipes is disabled and only TCP/IP is enabled. Authentication is set to Windows only. The server is in Active Directory.

    My web site is on a Windows 2000 server with IIS 5. I have installed the Client Network Utilities and set the alias to TCP/IP also. I can connect to the SQL server using the Query Analyzer.

    I have downloaded and installed ActiveState's ActivePerl 5.6.1.638-MSWin32-x86.msi on both machines. I have also installed DBI and DBD::ODBC on both machine. Both machine have MDAC 2.8 installed.

    The code I am using to connect is as follows:
    my $user = 'user';
    my $pass = 'password';
    my $db = "database";
    my $server = "servername\\instancename";
    my $ipadd = "xxx.xx.xx.xxx,xxxx";
    my $driver = '{SQL Server}';
    Option #1
    $DSN = 'driver=$driver;Server=$server;uid=$user;pwd=$pass ;database=$db;network=DBMSSOCN;address=$ipadd;';
    $dbh = DBI->connect("dbi:ODBC:$DSN") or die 'Cannot Open SQL Server Database $DBI::errstr\n';

    Option #2
    $DSN = 'driver=$driver;Server=$server;uid=$user;pwd=$pass ;database=$db';
    $dbh = DBI->connect("dbi:ODBC:$DSN") or die 'Cannot Open SQL Server Database $DBI::errstr\n';

    Option #3
    $dbh = DBI->connect('dbi:ODBC:driver=$driver:dsn',$user,$pass ) or die 'Cannot Open SQL Server Database $DBI::errstr\n';

    Option #4
    $dbh = DBI->connect("dbi:ODBC:database=$db;server=$server",$u ser,$pass) or die '$DBI::errstr\n';

    From all that I have read and from previous scripts I have written, any of these should work, but I am getting the following error.

    DBI connect('driver=$driver:dsn','user',...) failed: at C:\cgi-bin\CGI.pl line xxx Cannot Open SQL Server Database $DBI::errstr\n at C:\cgi-bin\CGI.pl line xxx.
    Where xxx = the line number of the connection call.

    All of my previous scripts have been written for forms where the web server(Apache), database(MySQL), and script(Perl CGI) are all on the same machine. I am not at all familiar with SQL Server, and am struggling to learn quickly. PLease and ideas would be greatly appreciated.
    Thank you
    LANAC

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    I don't know Perl, but VBScript would look very simple using Option #1:

    user = "user"
    pass = "password"
    db = "database"
    server = "servername\\instancename"
    ipadd = "xxx.xx.xx.xxx,xxxx"
    driver = "{SQL Server}"
    connect_string="driver=" & driver & ";server=" & server & ";uid=" & user & ";pwd=" & pass & ";database=" & db & ";network=dbmssocn"
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Try setting up a SQL Profiler trace on the database server. Trace all error/warning events, and see if you are getting anything at all from the client.

    I am afraid I have never worked with DBI, so I can not tell you if there is anything obviously wrong in the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •