Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 2nd May 2007, 11:22
pattchen pattchen is offline
Junior Member
 
Join Date: May 2007
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default hoow to connect to sql server from a script shell

hi,
I want to write a script shell which must connect to a sql server 2000 database. How may i achieve this?

thanks.
Reply With Quote
Sponsored Links
  #2  
Old 2nd May 2007, 17:31
abogothy abogothy is offline
Junior Member
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

from which platform ?
You can use freetds generally from *nix...
Reply With Quote
  #3  
Old 2nd May 2007, 19:05
pattchen pattchen is offline
Junior Member
 
Join Date: May 2007
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

i'm working with red hat linux 9.Thanks for your suggestion about freetds.I checked it on its web site,but there is not indication on HOW i can use it in a script shell.In fact, i'm a newbie in shell scripting,and so,i prefer an example(source code) .
May you help me for this issue?

thanks.
Reply With Quote
  #4  
Old 2nd May 2007, 20:57
abogothy abogothy is offline
Junior Member
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

Of course
First of all...check your SQL server security configuration. If only integrated security enabled (native windows authentication mode), you cannot connect to your database from linux.
MSSQL derived from Sybase, so MSSQL is compatible with Sybase tabbed stream protocol. You can use TDS to access mssql database.
Then download, extract and compile freetds:

wget ftp://ftp.ibiblio.org/pub/Linux/ALPH...tds-stable.tgz
tar xvfz freetds-stable.tgz
cd freetds-0.64
./configure
make
make install

If you want to run queries on MSSQL from linux, I propose you to use a simple perl script which connects to database, authenticates you on MSSQL server, runs a query then get back results to you,,,so you need a perl (included in your distro) and a sybase module...for example DBD::Sybase.
Start cpan and install DBD::Sybase module. Set SYBASE env variable to directory you've set previously (by default /usr/local used in freetds), then start DBD::Sybase installation from cpan.org:

export SYBASE=/usr/local/
cpan -i DBD::Sybase

cpan will download sources, and compile perl module, then it will run some tests with you settings (server name, user, password, and database)...
If you don't want to test on your compile machine, you can use "force install" with cpan...

So your machine contains freetds library and a perl module that uses it. A script examle that uses MSSQL from linux:

<- CUT HERE ->
#!/usr/bin/perl
#
use DBI;

my $dbh = DBI->connect("dbi:ODBC:JDBC", 'guest', 'sybase', {PrintError => 0});

die "Unable for connect to server $DBI::errstr"
unless $dbh;

my $rc;
my $sth;

$sth = $dbh->prepare("select \@\@servername");
if($sth->execute) {
while(@dat = $sth->fetchrow) {
print "@dat\n";
}
}

<- CUT HERE ->

Details described here: http://www.freetds.org/userguide/perl.htm#DBD.SYBASE
Reply With Quote
The Following User Says Thank You to abogothy For This Useful Post:
pattchen (7th May 2007)
  #5  
Old 7th May 2007, 22:01
pattchen pattchen is offline
Junior Member
 
Join Date: May 2007
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
 
Default

thanks for all,
i will try this today and post feedback later.
hope it will work .
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php Apps email not going through palkat General 8 21st September 2011 05:35
Statistic not working mzo Installation/Configuration 49 20th April 2011 12:19
Problems with Postfix Mysql Courier PatrickAdrichem Installation/Configuration 3 13th April 2007 15:44
Email - Ueb-Miau mazhar Installation/Configuration 5 21st December 2005 10:01
The Perfect Setup Suse 9.3 - Postfix problems new_bee05 HOWTO-Related Questions 20 25th November 2005 02:30


All times are GMT +2. The time now is 03:56.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.