Connecting to SQL Server on Windows

Shrenuj Bansal <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Organization http://groups.google.com
Message-ID <[email protected]>
I am using a perl script to try to connect to SQL Server on Windows. I believe I have DBI v1.607 and DBD::ODBC v1.25. I am able to connect to the server when I set up a data source using the ODBC Data Source Administrator on Windows. However, when I try to set up the data source myself in the perl script with the same credentials I get an error. I was hoping someone could help me out with this.

Here's my code:


use DBI;

# DBD::ODBC

my $dsn = 'DBI:ODBC:Driver={SQL Server}';
my $host = 
my $database = 
my $user = 
my $auth =

# Connect via DBD:ODBC by specifying the DSN dynamically
my $dbh = DBI->connect("$dsn;Server=$host;Database=$database",
						$user,
						$auth,
						{ RaiseError => 1, AutoCommit => 1}
						) || die "Database connection not made: $DBI:errstr";
						
# Prepare a SQL statement

my $sql = "SELECT BundleVersionLocation FROM valdb.dbo.VDB_BundleVersions WHERE BundleVersionID = 20";
my $sth = $dbh->prepare( $sql );

# Execute the statement
$sth->execute();

my($BundleVersionID);

# Bind the results to the local variables
$sth->bind_columns( undef, \$BundleVersionID );

# Retrieve values from the result set
while( $sth->fetch() ) {
	print "$BundleVersionID\n";
}

# Close the connection
$sth->finish();
$dbh->disconnect();

Here is the error I receive when I try to run the above script:

DBI connect('Driver={SQL Server};Server=ecmdrvdev-dbsql;Database=valdb','shrenuj
b',...) failed: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for
user 'shrenujb'. (SQL-28000) at test.pl line 13
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.