Connect to SQL Server in Perl and in VBScript

Say my database name is Jessica_DB, my user name is jessica, and my password jessica_pwd.


To connect to Microsoft SQL Server using Perl with Win32::ODBC module

use Win32::ODBC;
my $dsn = "DSN=Jessica_DB;UID=jessica;PWD=jessica_pwd;";
my $DB = Win32::ODBC->new($dsn);
$DB->Sql("SELECT f1, f2, f3 FROM MyTable");
($f1, $f2) = $DB->Data("f1", "f2");
print "f1 = ". $f1;


To connect to MS SQL Server using VBScript

Const adOpenStatic = 3
Const adLockOptimistic = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
 "Provider=MSDASQL.1;Data Source=Jessica_DB;" & _
 "Trusted_Connection=Yes;" & _
 "User ID=jessica;Password=jessica_pwd;"
objRecordSet.Open "SELECT * FROM MyTable", _
 objConnection, adOpenStatic, adLockOptimistic

Wscript.Echo objRecordSet.RecordCount


To connect in Python, check out pymssql


No comments yet. Why don’t you start the discussion?

Leave a Reply