ODBC Connection issue

Posted by venkeykanle on 2018-10-16 11:59

Hi,

System: Windows 2012 r2; x64; Perl 5.26.0 x86

The application is a classic ASP web hosted on iis 8.5.
Having issues in DB connection to SQL server; ODBCx32 DSN setup properly and it connects.

The DSN used in VBScript works great.. But the same DSN doesnt work in perl.
The error says:
F:\Test>perl TestODBC.pl
DBI connect('Sentinel','sentinel',...) failed: [Microsoft][ODBC SQL Server Drive
r][SQL Server]Login failed for user 'sentinel'. (SQL-28000) at TestODBC.pl line
12.

Could someone help to identify the error...
Thanks,
Venkatesh Kanale

Code sample below... both perl and asp/vbs.

F:\Test>
------------------------------------
Perl Code: (error in line DBI->connect

#!/usr/bin/perl
use strict;
use warnings;

use DBI;

my $dsn = "dbi:ODBC:Sentinel";
#my $dsn = "'dbi:ODBC:DRIVER={MS SQL Server Driver};Server=zneusu0n27se002;Database=Sentinel";
my $user = "sentinel";
my $password = "Welcome@43211";
my $dbh = DBI->connect($dsn, $user, $password);

# ...

#$dbh->do("INSERT INTO test_kanavm (name, city) VALUES ( 'One', 'Two')");

-------------------------
ASP/vbscript code: No error works fine.

<%@ language="vbscript" %>

<%

dim conn
set conn = Server.CreateObject("ADODB.Connection")
dim connString
connString = "DSN=sentinel; Uid=sentinel;Pwd=Welcome@4321"

conn.Open connString

dim rs
Set rs = CreateObject("ADODB.Recordset")

rs.open "SElect * from test_kanavm",conn

Do While NOT rs.Eof

response.write(rs("name"))
%>
<%
rs.MoveNext
Loop

rs.close
set rs=nothing
conn.close
set conn=nothing
%>

grahams
ActiveState Staff
Wed, 2018-10-17 09:15

The Perl code is supplying a DSN of "Sentinel", whereas the VB code is using "sentinel". These are not the same, and that could be your problem.