Strange behavior using Perl's system() function to query SQL Server with osql

Strange behavior using Perl's system() function to query SQL Server with osql

Post by Patrick Shroa » Sun, 21 Jul 2002 07:09:16



I have a script that uses Perl's system() fuction to execute an osql
command:

system("osql -Usa -Ppwd -Smyserver -Q\"select name from
master..sysdatabases\"");

That command dosn't work - it just displays the osql help page as
though I had made an error. However, the following command does work:

system("osql -Usa -Ppwd -Smyserver -Q\"sp_who2\"");

It returns the list of current SQL Server processes. What gives? Why
would it execute a stored procedure but not a simple select command?

Thanks!

 
 
 

Strange behavior using Perl's system() function to query SQL Server with osql

Post by Ali-Reza Anghai » Sun, 21 Jul 2002 08:26:09



> system("osql -Usa -Ppwd -Smyserver -Q\"select name from
> master..sysdatabases\"");

Don't you need to escape the "."s?

A very sick, -Ali

--
OpenPGP Key: 030E44E6
--
By the time they had diminished from 50 to 8, the other dwarves
began to suspect 'Hungry'... -- 'The Far Side', Gary Larson

 
 
 

Strange behavior using Perl's system() function to query SQL Server with osql

Post by Benjamin Goldber » Mon, 22 Jul 2002 12:24:47



> I have a script that uses Perl's system() fuction to execute an osql
> command:

> system("osql -Usa -Ppwd -Smyserver -Q\"select name from
> master..sysdatabases\"");

> That command dosn't work - it just displays the osql help page as
> though I had made an error. However, the following command does work:

> system("osql -Usa -Ppwd -Smyserver -Q\"sp_who2\"");

> It returns the list of current SQL Server processes. What gives? Why
> would it execute a stored procedure but not a simple select command?

Do any of the following work?
system(qw(osql -Usa -Ppwd -Smyserver -Qsp_who2));
system(qw(osql -Usa -Ppwd -Smyserver),
       "-Qselect name from master..sysdatabases");
system(qw(osql -Usa -Ppwd -Smyserver),
       "-Qselect name from master.sysdatabases");

system(qq(osql -Usa -Ppwd -Smyserver -Q"sp_who2"));
system(qq(osql -Usa -Ppwd -Smyserver ).
       qq(-Q"select name from master..sysdatabases"));
system(qq(osql -Usa -Ppwd -Smyserver ).
       qq(-Q"select name from master.sysdatabases"));

Also, have you considered doing:
use DBI;
my $dbh = DBI->connect(
   "DBI:ODBC:myserver",
   "sa", "pwd",
   {RaiseError => 1},
) or die $DBI::errstr;
my $sth = $dbh->prepare(
   qq(select name from master.sysdatabases)
); # or maybe master..sysdatabases
$sth->execute;
while( my ($name) = $sth->fetchrow ) {
   print $name, "\n";

Quote:}

__END__

[all untested]

--

pack 'u', pack 'H*', 'ab5cf4021bafd28972030972b00a218eb9720000';

 
 
 

Strange behavior using Perl's system() function to query SQL Server with osql

Post by Bart Lateu » Mon, 22 Jul 2002 22:26:10



>I have a script that uses Perl's system() fuction to execute an osql
>command:

>system("osql -Usa -Ppwd -Smyserver -Q\"select name from
>master..sysdatabases\"");

>That command dosn't work - it just displays the osql help page as
>though I had made an error.

Is that really supposed to be two dots?

--
        Bart.

 
 
 

1. Not sure where to put this--strange ODBC behavior (or I think it's strange)

I have a database that writes to a SQL 7 table through
ODBC (Access 2000).  The main server went down and we were
able to, relatively quickly, move to the backup server
(I'd been making backups all along and storing them off
the main database server, so it wasn't a problem to
retrieve them).

All was working well with the backup server, despite it
being slower than molasses in winter, and we finally got
the main server back up.  In the meantime, the Acc 2000
application was used again.  I didn't change the server
name to the main server (it had been on the backup
server's name), but all of a sudden I saw that data was
being written to the main server again.  How could this be
without me changing anything on the client machine (I did
change my machine back to point to the main server, but
not the machine from which the client application runs)?  
The client app had been writing to the backup server.

We are using TCP/IP connectivity, no cluster services,
with the SQL 7 Driver for ODBC, to connect between the
client and the server.  I specified the machine name MAIL1
(the backup server) for the ODBC data source.

The problem with all of this is that the client seems to
be going back to the server before I get a chance to
restore from backup (so that the data that was written to
the backup server is now in the main server), and this
causes problems going forward.

2. Missing ' (<x> row(s) affected)' from stored procedure

3. strange behavior in SQL SP and SQL Query Analyzer

4. How is possible to prevent table overflow?

5. Different behavior between Query Analyzer and OSQL utility

6. SQL Server 7.0 GPF with VB3 ODBC

7. Strangest SQL 7.0 Query Analyzer behavior ever

8. An distributed OO database based on CLOS.

9. Using Win32odbc for PERL for NT to query SQL-Server 6.5

10. Strange Behavior - ADO and SQL Server 6.5

11. Strange behavior of SQL Server for exception handling

12. NZ Function In access Strange Behavior

13. Strange behavior in SQL server