I am running the following OSQL command and capturing the return code
for the error .Whenver i have an error like server not exists or uable
to login I get a return code of 1 for the %ERRORLEVEL%.Ho wever
whenever I have an errorof a wrong dbcompatibility error the retun
code id 1 even though sql returns an iformation message from OSQL that
the right copatibilty levels are 60,70 and 80.How can i get OSQL to
return the right return code whenver a error of this type occurrs from
batch mode sql.The OSQL i am running from the batch is
osql -S%SrvName% -U%Username% -P%Userpswd% -n -w 132 -d%DBname%
-Q%sqlcmd% -o%Dirrpt%\%DBna me%_%SPname%.tx t
ECHO %errorlevel% >> %logbatch%
IF %ERRORLEVEL% NEQ 0 Goto SQLError
sqlcms is exec sp_dbcompatibil tylevel srvrname, dbname 80
Thanks in anticipation.
Ajay 3 14053
[posted and mailed, please reply in news]
Ajay Garg (aj*****@hotmai l.com) writes: I am running the following OSQL command and capturing the return code for the error .Whenver i have an error like server not exists or uable to login I get a return code of 1 for the %ERRORLEVEL%.Ho wever whenever I have an errorof a wrong dbcompatibility error the retun code id 1 even though sql returns an iformation message from OSQL that the right copatibilty levels are 60,70 and 80.How can i get OSQL to return the right return code whenver a error of this type occurrs from batch mode sql.The OSQL i am running from the batch is
osql -S%SrvName% -U%Username% -P%Userpswd% -n -w 132 -d%DBname% -Q%sqlcmd% -o%Dirrpt%\%DBna me%_%SPname%.tx t ECHO %errorlevel% >> %logbatch% IF %ERRORLEVEL% NEQ 0 Goto SQLError
sqlcms is exec sp_dbcompatibil tylevel srvrname, dbname 80
Here is a simple example that illustrates:
E:\temp>osql -E -n -Q "EXIT (SELECT 47)"
-----------
47
(1 row affected)
E:\temp>echo %ERRORLEVEL%
47
E:\temp>
By putting the entire SQL batch within EXIT(), OSQL will return the
value of the last result set to the command-line environment.
For details, see the topic on OSQL in Books Online.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Erland Sommarskog <so****@algonet .se> wrote in message news:<Xn******* *************** @127.0.0.1>... [posted and mailed, please reply in news]
Ajay Garg (aj*****@hotmai l.com) writes: I am running the following OSQL command and capturing the return code for the error .Whenver i have an error like server not exists or uable to login I get a return code of 1 for the %ERRORLEVEL%.Ho wever whenever I have an errorof a wrong dbcompatibility error the retun code id 1 even though sql returns an iformation message from OSQL that the right copatibilty levels are 60,70 and 80.How can i get OSQL to return the right return code whenver a error of this type occurrs from batch mode sql.The OSQL i am running from the batch is
osql -S%SrvName% -U%Username% -P%Userpswd% -n -w 132 -d%DBname% -Q%sqlcmd% -o%Dirrpt%\%DBna me%_%SPname%.tx t ECHO %errorlevel% >> %logbatch% IF %ERRORLEVEL% NEQ 0 Goto SQLError
sqlcms is exec sp_dbcompatibil tylevel srvrname, dbname 80
Here is a simple example that illustrates:
E:\temp>osql -E -n -Q "EXIT (SELECT 47)"
----------- 47
(1 row affected)
E:\temp>echo %ERRORLEVEL% 47
E:\temp>
By putting the entire SQL batch within EXIT(), OSQL will return the value of the last result set to the command-line environment.
For details, see the topic on OSQL in Books Online.
I noticed someting even more interesting.Eve n though the return code
was 0
when there was an error the job on sql server which actually failed
showed that it ran sucessfully.Eve n though when i run the job as an
Xp_cmdshell command on the sql server it shows that it failed what
could be the reason that it behaves that way?
Thanks in anticipation.
Ajay
Ajay Garg (aj*****@hotmai l.com) writes: I noticed someting even more interesting.Eve n though the return code was 0 when there was an error the job on sql server which actually failed showed that it ran sucessfully.Eve n though when i run the job as an Xp_cmdshell command on the sql server it shows that it failed what could be the reason that it behaves that way?
I'm sorry, but I don't follow. Could you clarify with an example?
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob |
last post by:
Everybody,
I've been doing a lot of on-line research and cannot find
any reference to the exact problem I'm having.
Let me preface this question with the fact that I'm coming
from an Oracle background so my approach may not be the best
way to tackle this. However, from the research I have done
this approach seems reasonable. Also, I know about the
undocumented procedure sp_MSforeachtable. That can give me a
|
by: Murtix Van Basten |
last post by:
Hi,
I have dumped a very large database from mysql (using mysqldump program)
as a raw sql file. The reason was, convert this database to a MSSQL
database. Since mysqldump creates the file as raw sql file with the
database-table structures and the data in it, I thought using OSQL command
line utilities should work to out this whole database in MSSQL server.
I have run this command from command line:
|
by: David |
last post by:
Does anyone know where I can find example code for VB.NET that I can use
to create an application that attaches and detaches databases to MSDE using
osql scipts.
(I think SQL-DMO is typically used)
Thanks in advance
|
by: arfanameer |
last post by:
I have to create database usign OSQL. i am usin a command like this
C:> osql -E -i db1.sql
But it doesnt create database and returns error saying user login
failed for administrator whereas I have no user for SQL server n it
uses by default . I also tried with sa username by entering it with -U
switch in command but still it gaves same error. Can anyone help me
|
by: arfanameer |
last post by:
How can I create a new database on sql server using OSQL command in
command prompt. I have the sql file for database creation and I use the
following command
C:\> osql -S servername -U sa -i db1.sql
it prompt my for password n i enter it since sa has a blank password
but after that it returns the following error.
1> 2> 3> Msg 170, Level 15, State 1, Server servername, Procedure ,
Line 2
| |
by: Tiago Costa |
last post by:
I want to call a OSQL command to BackUp my data base, how can i call it from
Visual Studio (C#) 2003.
Thanks In Advance,
Tiago Costa
|
by: |
last post by:
Hi,
I have just started using MSSQL and the DOS environment at work. I have
a lot of experience with Sybase and the UNIX environment, but this is a
whole new ball of wax.
I'd like to use osql from a batch file to log into the dataserver and
run a fairly long list of SQL and then exit. I don't want to have a bunch
of SQL files sitting around that I have to use the -i option to run, and
I'd rather not create temporary SQL files like...
|
by: David R. |
last post by:
Hello all,
I would like to generate a Sql-Script-File and a Batch-File to execute the
Batch-File over C#-Code and use the SQL-File as an Input-File for the command
"osql" in the Batch-File.
I generate the two files "attachDB.sql" and "setup.bat" with the following
code:
AttachAtpDBFile = File.CreateText(@"c:\attachDB.sql");
AttachAtpDBFile.AutoFlush = true;
|
by: gopal |
last post by:
Hi,
I have a console application whose purpose is to run the OSQL utility
from
my console application.
When my application is run, the OSQL utility is started and it has to
prompt for Database UserName & Password .
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |