473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How do I access a SQL Server database from a Perl script in Linux?

I'm not able to insert the value into a SQL Server database from a Perl script in Linux
code is given below:

#!/usr/bin/perl

use strict;
use DBI;
use Data::Dumper;
use Asterisk::AGI;

my $agi = new Asterisk::AGI;

my $fifth_param = "22";
my $first_param = "04-09-2012";
my $second_param = "04-09-2012";
my $third_param = "2002";
my $forth_param = "0123";

my $DSN = q/dbi:ODBC:SQLSERVER/;
my $uid = q/ivr/;
my $pwd = q/ivr/;

my $DRIVER = "Freetds";
my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't Connect SQL";
# my $servernumber = 2;

# my ($dbname) = $dbh->selectrow_array("select DATABASE()");
eval
{
my $td = $dbh->do(q/USE CServer/);
# print "$td\n";
};

my $sql = "Insert into dbo.winast_outbound_callmaster (out_call_number,out_start_time,out_end_time,out_e xtenstion,out_CLI) values('$fifth_param','$first_param','$second_para m','$third_param','$forth_param')";


my $sth = $dbh->prepare($sql);
my $sth->execute() or die $dbh->errstr;


my $return = $sth->fetchrow();
my $agi->set_variable('result',$return);
print Dumper($return);


$sth->finish;
$dbh->disconnect;


I got this error :-

Can't call method "execute" on an undefined value at Outgoing_Call.agi line 45.
Jun 12 '12 #1

✓ answered by RonB

I also suggest that you adjust your error handling. As is, it's ok for command line testing, but when used as an agi script, you won't see those error messages in either the asterisk cli or cdr file.

4 3001
RonB
589 Expert Mod 512MB
Your execute statement is on line 35 and there is no line 45 in the code you posted, so that error message was not generated by the script you posted.

Why are you using that eval block? Take that out and instead specify the database in the connect statement.

You should also add vertical whitespace to the sql statement to add readability and, you should use placeholders and put the values in the execute statement.
Jun 12 '12 #2
RonB
589 Expert Mod 512MB
I also suggest that you adjust your error handling. As is, it's ok for command line testing, but when used as an agi script, you won't see those error messages in either the asterisk cli or cdr file.
Jun 12 '12 #3
@RonB
Sir,

how can i identify that table is belong in which database that why i have used eval statement.In my sql server have many databases.
I have put vertical whitespace and placeholders but it is showing same error.
Please help me..
Jun 13 '12 #4
i got the solution thanks for the help
Jun 13 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
6
by: Richard Trahan | last post by:
I want a js function to call a Perl script residing on a server. The Perl script will return a string, to be used by the js. Pseudo code: <script> stringvar = perlfunc_on_server(stringarg)...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
4
by: jonniethecodeprince | last post by:
Greetings all. I have a problem with PERL and SQL Server. I need to upload a database query to a web page using PERL and SQL Server. I have tried to do this myself but nothing displays on the...
5
by: Perl Beginner | last post by:
Hello all, I have written a pretty lengthy Perl script using Win32. Now i need to take this same script and run it on a Linux operating system. I'm not familiar with Linux at all, so I've been...
3
by: tundal45 | last post by:
Hey Guys, I am trying to automate the process of loading data in our oracle server. As a part of that process, I am working on a perl script that loads external tables from data files. What I am...
82
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a)...
7
by: sammak168 | last post by:
I had a Perl script that called a sql file calling the stored procedure in Oracle database. The stored procedure ran for a long time (more than 1.5 hrs) and did not return the result code to the...
1
by: rash123 | last post by:
Hi all, I have written one perl script to create and then change ownership of a folder in Linux platform.Folder got created ,but got error as :chown: changing ownership of folder:Operation not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.