Solved

Connecting Perl to MS SQLserver

Posted on 2012-03-28
2
488 Views
Last Modified: 2012-04-13
Hi,
 
i need a working example step by step how to connect Perl to MS SQLSERVER

regards,
0
Comment
Question by:zakwithu2012
2 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37776067
0
 

Author Comment

by:zakwithu2012
ID: 37781098
Thank you for the links...

Can anybody tell me what is wrong in my below code:

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

my $db_instance = "HIPCCMGMT";
my $db_name = "CDR_CUCM7_1_5";
my $db_user = "sa";
my $db_pass = 'MyPassword'; 
my $dbh = DBI->connect("DBI:ODBC:Driver={SQL Server};Server=$db_instance;Database=$db_name;UID=$db_user;PWD=$db_pass") 
or die("\n\nCONNECT ERROR:\n\n$DBI::errstr");

my %hash = (             
1   =>  "A",             
2   =>  "13"            
);  

my @keys = keys %hash;  
my @values = values %hash;  
my $sth = $dbh->prepare("INSERT INTO DevicesData(DeviceName, DataValue) VALUES (?,?);");  
$sth->execute_array({},\@keys, \@values); 
$dbh->disconnect;

Open in new window


I'm getting this error:
C:\>perl test.pl
DBD::ODBC::st execute_array failed: executing 2 generated 1 errors at test.pl li
ne 23.

Open in new window

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Oracle SQL with Connect by prior to SQL Server SQL 6 31
SQL Select - Help with CASE 4 42
Nested cursor  in SQL 9 94
SQL FUll Text Not returning any results 2 15
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now