473,700 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

13 New Member
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:SQLSER VER/;
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_arra y("select DATABASE()");
eval
{
my $td = $dbh->do(q/USE CServer/);
# print "$td\n";
};

my $sql = "Insert into dbo.winast_outb ound_callmaster (out_call_numbe r,out_start_tim e,out_end_time, out_extenstion, out_CLI) values('$fifth_ param','$first_ param','$second _param','$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.a gi line 45.
Jun 12 '12 #1
4 3013
RonB
589 Recognized Expert Moderator Contributor
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 Recognized Expert Moderator Contributor
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
omakhileshchand
13 New Member
@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
omakhileshchand
13 New Member
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
10196
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 4 12 24 42 64 92 124 162 204 252 4 11 23 44 67 95 134 168 215 271 ..
6
15896
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) document.write(stringvar) </script> Can stringvar above be a url?
9
20894
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 rapidshare news : http://images.rapidshare.com/software/rsapi.pl If you test it you will see that you can upload one file at time. I try to modify it in that way that script can read a text file with the names of the files i want to...
4
4151
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 page. The .CGI file will call the PERL but does not display any of the results of the query search via SQL Server on my page. I have commented out the output I wanted because this causes an Internal Server Error. I realise that this is a very basic...
5
1583
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 researching it for a few days. I feel like it's a little over my head. Or am I looking too much into it? Or maybe I'm looking in the wrong places. Is there a straightforward way to convert this script and run it on Linux? Or can anyone direct me to...
3
4037
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 seeing is that I get following error when I select from external table created using script. ORA-29913: error in executing ODCIEXTTABLEOPEN callout ORA-29400: data cartridge error KUP-00554: error encountered while parsing access parameters...
82
10027
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) html b) perl script (print and inserting into database) Cheers... Andrew
7
2689
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 perl script. (I could see from the job log of the stored procedure that the stored procedure was successfully completed) my $sql = "sqlplus -s userid/password $jobId"; $rtnCode = system($sql); I had other similar jobs that ran shorter time (e.g....
1
2021
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 permitted Since this perl script has only local user privilege ,it is not allowing to change ownership of folder.If i run script as root ,it is working fine. But i want to run this script as local user.Is there any way to give chown privilege ...
0
8642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9066
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8916
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7802
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5899
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2383
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.