Osql Batch Processing Without -i

Jan 17, 2006

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 this.

echo "exec sp_who2" >tmp.sql
echo "select * from....... " >>tmp.sql
osql -E -S <DATASERVER> -n -w999 -i tmp.sql
del tmp.sql

I can't use the -Q option, of course because as I said, I'll be writing
quite a few lines of SQL, and it won't all fit on the one line, or at least
it wouldn't be pretty if I did.

In UNIX, I can simply execute the following from either the command line
or in
a script.

isql -S<DATASERVER> -U<USER> <<-EOF

sp_who
go
select * from .....
go
EOF --EOF is the isql session terminator exits me back to the command line.

This behavior does not appear to work with OSQL. There is a -O option
which help mentions, and that talks about disabling the EOF terminator for
batch processing, but I wasn't able to find any usage or examples on the net
where someone is using EOF to terminate their OSQL SQL batch.

This is what help listed.
[-O use Old ISQL behavior disables the following]
<EOF> batch processing
Auto console width scaling
Wide messages
default errorlevel is -1 vs 1


Any help you could offer would be appreciated. Thanks.

Darren

View 2 Replies


ADVERTISEMENT

Osql Batch Slow

Jun 3, 2008

Have a osql batch when i run it on my desktop its fast. then when i run it on the server is very slow.
Any ideas? how to solve it?

MCTP

View 3 Replies View Related

OSQL Batch File Problem

Aug 22, 2006

I have a scheduled task that runs a batch file in windows 2003 server which
is running SQL Server 2000 Enterprise.

The batch file contains the line:

OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log

the 'myscript.sql' file updates a table with another table of the exact
number of rows.

When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
affected.

If I run this myself from the command line, 22,000 rows are affected which
is correct.

I am guessing there is some sort of permission/authentication issue here. I
am sending the right username/password for SQL and for windows to run the
task.

Any idea what I could do to fix this?

Thanks,

Nitrox

View 1 Replies View Related

Executing Osql Commands Through Batch File

Sep 13, 2006

Hello

I have a script ,which runs with osql

The script is :

osql -E
declare @cmd nvarchar(1000)
declare @cmd2 nvarchar(1000)
declare @state1 varchar(100)
declare @message varchar(100)
set @message = ''
-- Build command to determine state of SQLSERVERAGENT service on Master Server
SET @CMD = 'create table #state (state varchar(2000))' + char(10) +
'declare @cmdx varchar(1000)' + char(10) +
'insert into #state EXEC master..xp_servicecontrol ''''QueryState'''', ''''SQLSERVERAGENT''''' +
+ char(10) + 'select @state=state from #state' + char(10) +
'drop table #state'
-- Build command to execute command that determines state of service being monitored
set @cmd2 = 'declare @state varchar(100)' + char(10) +
'exec ' + rtrim(@@servername) + '.master.dbo.sp_executesql N''' + @CMD + ''',' +
'N''@state varchar(100) out'',' +
'@state out' + char(10) +
'set @state1 = @state'
-- Execute command and return state of service being monitored
exec master.dbo.sp_executesql @cmd2,N'@state1 varchar(100) out',@state1 out
-- Is the service that was monitored not
IF (UPPER(@state1) <> 'RUNNING.')
--if @state1 <1 'Running.'
begin
-- Display message that primary monitor is down
select @message = @message+char(13)+ @@servername + ' -' + 'Sql Server Agent Not Running'+char(13)
print 'Master server "' + rtrim(@@servername) + '" for monitoring is not available.'
exec master.dbo.xp_smtp_sendmail

It works fine when I run it on the command line prompt.
And I receive a mail , if the server agent is running.

But when I save it as bat file and try to run , it stops and doesnot even give an error.

Can anyone let me know what I can do.

Thanks

View 1 Replies View Related

Formatting Question With Osql Batch File

Jul 23, 2005

Hi all,This is my first batch file and I want to query a database and outputit in a textfile. Up to now that works, the only problem is theformatting in the text file. It's all screewed up...lines aren't linedup and columns aren't right....how do you format the result from aquery to a text file. Here's my code:osql.exe -S MYMACHINE -w 30 -E -d Demo2 -Q "select * from Title wherefrequency = 'monthly'" -o "C:output.txt"Thanks....JMT

View 1 Replies View Related

DOS Batch File Running Osql - Opening/closing Connections

Jul 20, 2007

I've written a small dos batch script that runs a simple query throughosql and then calls an exe which sends an email if the returned value


Quote:

View 2 Replies View Related

Activated Stores Procedure And Batch Processing

Aug 2, 2006

Hi There

2 Questions :

1. Almost in every SB example you will see this sql :

BEGIN TRANSACTION

WAITFOR (

RECEIVE TOP (1)

@MessageType = message_type_name,

@Message = message_body

FROM [Queue1]

WHERE conversation_handle = @ConversationHandle

), timeout 5000;

If this sql in an activated sp do you really have to have the waitfor ? Since the sp will only be fired if there is a message on the queue ?

2. It is reccomended that for high volume SB apps you do not do a top(1) receive but process batches. Exactly what is the best practice to do this. Receive a batch into a table variable and then what ? Process through it with a cursor ? That is not very efficient either, i would just like some insight into batch queue processing as everywhere i have seen uses top (1) from the queue ?

Thanx

View 3 Replies View Related

How To Launch MSOLAP Cube Processing In Batch Mode?

Mar 12, 2001

Jonathan Yang Jonathan.Yang@Weyerhaeuser.Com

How to launch MSOLAP cube processing in batch mode?
================================================== =

When one wants to run SQL Statement or Stored procedure in batch mode, OSQL.exe can be used.

Now we have created OLAP cube and want to process(populate) cube. From MSOLAP Analysis manage we can right click a cube name then click “Process”. But how to do this in batch mode? I.e. any equivalent thing of OSQL.exe to help process cube?

I believe a matured tool should work good in both interactive and batch mode. Unfortunately I did not find how to launch cube processing from MS OLAP documents. Looks like we have to write one using DSO supplied by Microsoft. Do you know if there is any tool for us not to write one? Pls help.

View 1 Replies View Related

TSQL + VBA Excel 2003 - Importing Data From MS Excel 2003 To SQL SERVER 2000 Using Multi - Batch Processing

Sep 11, 2007

Hi,
I need to import an SQL string from MS Excel 2003 to SQL SERVER 2000.
The string I need to import is composed by 5 different several blocks and looks like:



Code Snippet

CommandLine01 = "USE mydb"
CommandLine02 = "SELECT Block ..."
CommandLine03 = "GO
ALTER TABLE Block...
GO"
CommandLine04 = "UPDATE Block..."
CommandLine05 = "SELECT Block..."

The detail of the SQL string is at:
http://forums.microsoft.com/msdn/showpost.aspx?postid=2093921&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=1



I am trying to implement OJ's suggestion:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2117223&SiteID=1
to use multi - batch processing to import the string to SQL SERVER, something like:




Code Snippet
Dim SqlCnt, cmd1, cmd2, cmd3
'set the properties and open a connection

cmd1="use my_db"
cmd2="create table mytb"
cmd3="insert into mytb"

SqlCnt.execute cmd1
SqlCnt.Execute cmd2
SqlCnt.Execute cmd3

Below is the code (just partial) I have, and I need help to complete it.
Thanks in advance,
Aldo.




Code Snippet
Function TestConnection()
Dim ConnectionString As New ADODB.Connection
Dim RecordSet As New ADODB.RecordSet

ConnectionString = "Driver={SQL Server};Server=myServer;Database=myDBName;Uid=UserName;Pwd=Password"
ConnectionString.Open

CmdLine01 = " USE " & myDB
CmdLine02 = " SELECT ACCOUNTS.FULLNAME FROM ACCOUNTS" ...

CmdLine03 = "GO
ALTER TABLE Block...
GO"

CmdLine04 = "UPDATE Block..."
CmdLine05 = "SELECT Block..."

RecordSet.Open CmdLine01, ConnectionString
RecordSet.Open CmdLine02, ConnectionString

ConnectionString.Execute CmdLine01
ConnectionString.Execute CmdLine02

'Retrieve Field titles
For ColNr = 1 To RecordSet.Fields.Count
ActiveSheet.Cells(1, ColNr).Value = RecordSet.Fields(ColNr - 1).Name
Next

ActiveSheet.Cells(2, 1).CopyFromRecordset RecordSet

'Close ADO objects
RecordSet.Close
ConnectionString.Close
Set RecordSet = Nothing
Set ConnectionString = Nothing

End Function






View 7 Replies View Related

Passing Parameters To Batch File And Executing Batch File Loop

Aug 7, 2007

HELP,

I need to take a variable from a tabel in SQL Server pass to a Batch file and execute the batch file. Right now I can exec the batch file with XP_CMDSHELL but how can I pass the variable to the batch file and loop through all the variables.

Please help

Phil

View 4 Replies View Related

SQLCMD Batch File With Script In Batch File

Dec 5, 2006

I am using the following batch file to execute a script that creates a db and all its objects in the local sql express:

sqlcmd -S (local)SQLExpress -i C:CreateDB.sql

This works fine, but I'm wondering if there's an easy way to put the script in the batch file, so users don't have to worry about putting the script in the C drive. I tried getting rid of the i parameter and pasting the script from the sql file into the batch file, but it didn't work.

Thanks,

Dave

View 1 Replies View Related

Osql

Jun 28, 2001

Hi, we are having problems getting osql to work. When we try and open it quickly opens and then closes again. Has anybody else had this problem?

View 1 Replies View Related

Osql

Oct 25, 2004

Hi all.

My first post here.

I want to distriburte a msde database. When doing so, I also want to make a new login, make a user, make the user the dbowner of the database i installed.

I found the Stored procedures I need to use, and I have tested that it works using OSQL.

What I want to do now is to make this automatic. After installing the database the OSQL commands should be executed and no user interference should be necessary. How can that be done ?

peet

View 4 Replies View Related

OSQL Help

May 15, 2008

Hi All,

I am trying to use OSQL (somthing I am new too)

I have the folllowing syntax, but it does not seam to work. Any ideas would be very gratfull.

osql -Usa -Ppassword -SServername -Q"select @@version"

Thanks in advance

Dave


Dave Dunckley says there is a law for the rich and a law for the poor and a law for
Dirty Davey.

View 7 Replies View Related

OSQL

Mar 11, 2008

Hello,

I have several sql scripts to be executed on a set schedule, with the output directed to a text file. If the schedule triggers this process daily, is it possible to append each days output to the same output file? I've researched the osql switches and various online sources...nothing really covers this.

This is done (relatively) easily with .vbs, but so far it looks tougher with TSQL.

Many thanks to all who respond!

View 2 Replies View Related

Osql

Mar 12, 2008

is there some way to activate osql from a c++ app and stream theoutput to my program?

View 1 Replies View Related

Osql

Dec 22, 2006

i'm trying to execute some scripts created by the express studio script wizard. i can connect with the studio, the website (asp worker) but i can't create the right cmdline for osql ..... this is my osql line ......

C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLBinn>osql -S (local)\SQLEXPRESS -U sa -P sablah -i run.sql.......

this is the error i'm getting in my logs

Error: 18456, Severity: 14, State: 16.
2006-12-22 15:30:45.11 Logon Login failed for user 'sa'. [CLIENT: <local machine>]

"Server=(local)\SQLEXPRESS;Database=ggmi;User Id=sa;Password=cr79cr02;Trusted_connection=false;";

the following is the working connection string for my aspworker.

"Server=(local)\SQLEXPRESS;Database=ggmi;User Id=sa;Password=cr79cr02;Trusted_connection=false;";

when i try to put in the trust conenction parameter is says that it conflicts with the user flag ,. probably because its a differant type of login process. any ideas?

View 6 Replies View Related

Osql Utility

Jul 28, 2004

using osql utility i have converted a table in database to excel format. I have also chinese data in my database . The problem is while converting the data into excel format ,the chinese data is not comming in excel sheet.
Does anybody have an idea about this .
For converting i have used

declare @x varchar(300)
set @x = 'osql -S Servername -U username -P passwd -q "select * from northwind..region order by cand_index" -w 3000 -s "," -o C:directoryfilename.csv'


Thanks

View 2 Replies View Related

Osql Utility

Aug 14, 2004

Hi all
I am using osql utility in sql server 2000 to convert data in database to excel sheet. My datas contain both english and chinese . While converting to excel sheet english datas are comming but the datas in chinese is comming like (?) this. Does any body has any idea to solve this problem. is there any way to set font in osql utility.

set @x = 'osql -S servername -U username -P password -q "select * from

northwind..region" -w 3000 -s "," -o C:Downloaddownload.csv'
This is what i have used.
Note: I tried giving chinese font in excel still it is not working.
Its really urgent pls reply
thanks

View 2 Replies View Related

Osql Syntax Help

Oct 8, 2004

Dear friends,

I was trying to run this script from a dos batch file under win xp but it's not working. Please help with the syntax.
================================================== =======
OSQL -U sa -P samsde -S firebird /Q "RESTORE DATABASE NAVIMEX FROM DISK = 'C:30704' WITH

REPLACE, MOVE'NAVIMEX_Data' TO 'C:Program FilesMicrosoft SQL

ServerMSSQLDataNAVIMEX_Data.MDF',MOVE 'NAVIMEX_Log' TO 'C:Program FilesMicrosoft SQL

ServerMSSQLDataNAVIMEX_LOG.LDF'" QUIT
================================================== ========

Please provide me with the correct syntax to be put in a 'restore.bat' file :rolleyes:

Thanks in advance.
HotBird

View 4 Replies View Related

Osql -b Question!

Oct 25, 2004

the help document said that

"osql -b will specifies that OSQL exits and returns a DOS ERRORLEVEL value when an error occurs. The value returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity of 10 or greater; otherwise, the value returned is 0."

my question is : how can I get the DOS ERRORLEVEL.

example:

C:>isql -E -b -Q"backup log pubs to disk='C:adsfasd.tmp'"

the result:

Msg 4208, Level 16, State 0, Server YANG, Line 1
当恢复模型为 SIMPLE 时,不允许使用 BACKUP LOG 语句。请使用 BACKUP DATABASE 或用
ALTER DATABASE
更改恢复模型。
Msg 3013, Level 16, State 1, Server YANG, Line 1
BACKUP LOG 操作异常终止。

It's in chinese language,means
"can not use BACKUP LOG when the restore model being SIMPLE,you can use ALTER DATABASE or BACKUP DATABASE to change the restore model.
Msg 3013, Level 16, State 1, Server YANG, Line 1
BACKUP LOG aborted"

where is DOS ERRORLEVEL???? How can I get it????

thanks

View 2 Replies View Related

Running A Job Via Osql??

Dec 1, 2004

Hello All,
A VERY green SQL Server DBA here looking for some help. Our main production environment is Oracle, which utilizes Control-M as a scheduler. At the end of the Oracle batch process, we would like to automate a process to kick off a sql server job (perhaps via osql??) Is this possible?

Thanks in advance,
Tony

View 14 Replies View Related

Osql And Carc.:éàè

Dec 14, 2005

I run a script with Osql and got no error but the accent caracter (french message) are modified.

the script is
CREATE PROCEDURE dbo.AccentTest
AS
Print('é à è î ï ù')
GO
and come
CREATE PROCEDURE dbo.AccentTest
AS
Print('Θ α Φ ε ∩ ∙')
GO
:o
This is very bad! Can someone can help me?
Any suggestion?
PLease.....


osql.exe -S MyServer -U username-P pwd-d TestDB -n -o "C:Devosql_test.log" -i "C:DevAccentTest.sql" :

View 1 Replies View Related

Dynamic SQL Vs OSQL

Sep 5, 2006

Question for the experts here:

Is there any advantage of running an SQL statement through osql with the database information over using dynamic sql?

Example:

DECLARE @DB Varchar(50)
DECLARE @SQL Varchar(4000)
SET @DB = '<nvr_changing_server>.<my_dynamic_db_name>'
SET @SQL = 'SELECT admissiontype_id AS atype, admissiontype AS atype_desc, start_date, end_date
INTO tlkAdmitType
FROM <nvr_changing_server>.<nvr_changing_DB>.dbo.tlkAdmissionTypes'

exec master..xp_cmdShell 'osql -U sa -P sapwd -S nvr_changing_server -d my_dynamic_db_name -Q @SQL....'

vs. something like:

DECLARE @DB Varchar(50)
DECLARE @SQL Varchar(4000)
SET @DB = '<nvr_changing_server>.<my_dynamic_db_name>'
SET @SQL = 'SELECT admissiontype_id AS atype, admissiontype AS atype_desc, start_date, end_date
INTO ' + @DB +'.dbo.tlkAdmitType
FROM <nvr_changing_server>.<nvr_changing_DB>.dbo.tlkAdmissionTypes'

EXEC(@SQL)

The purpose of all this is...I need to pass a parameter for the DB that I will be inserting into...here we create a new db with a specific name based on quarterly data. We collect, crunch, validate data and ship it. Then when it's old we archive it then eventually delete it.

I have written a script that makes this quarterly build less painful. In fact I won't have to do it! :)...our Sr. Data Analysts will do it now. In order for this beautiful thing (*in my mind anyway*) to work they need to set parameters for which data to pull and where to put it. The DB is scripted into existance and the data is moved into it. So therefore they need to enter the Qtr,Yr and dbname. I have done DSQL before on smaller scripts and I am just curious if the expert pool here can shed some light on this approach. The script will most likely be run in a DTS SQL Task.

Thanks in advance...R

View 1 Replies View Related

Running OSQL

Feb 25, 2004

Hi,

When i want to run the OSQL utility, it will open the command prompt, but only for about a second, then, gone...

I'm running an XP pro machine with MSDE 2000 installed locally... any ieads??

thanks!

View 2 Replies View Related

OSQL Question

Mar 18, 2004

I created a sql script that transfers data from my test system to production adn vice versa. I would like to use OSQL and be able to pass parameters to the SQL script.

Example: param 1 = test; param 2 = production.

Can anyone tell me if this is possible and how to do it?

Thanks in advance for all the help.

View 2 Replies View Related

Error With Osql

Apr 21, 2004

Locally executing osql to create db files on a remote Webserver, I get this error:

41> 42> 43> 44> 45> Meldung 916, Ebene 14, Status 1, Server USER-EQ9OV60EMF, Zeile 12
Server user 'Robse_Testlogin' is not a valid user in database 'msdb'.

(The above is german and translates into "Message 916, Level 14,..., Row 12")

This is the command with parameters:

osql -S servername -U Robse_Testlogin -P password -i c:Storestoredb.sql"


Up to that line, everything works fine...what could be wrong?

View 3 Replies View Related

Osql Formatting

May 5, 2004

At first I'd like to justify myself - I'm rather a greenhorn in MS SQL ;-)
What I'd like to do is to create a very simple spool file from my database.
I'd like to do this using OSQL tool and it's very important for me to have the spool file in the same format as it was earlier when I used Oracle and simple spool command.
And it's almost the same, but white spaces...
There's always one white space at the begining of each line and at least one at the and of each line.
I've been trying many OSQL switches and ltrim(..) / rtrim(..) functions but the problem still exists...
The spool file is rather big - around 300MB so it's not good idea to use SED (for example) to remove white spaces.
So my question:
IS IT POSSIBLE TO REMOVE WHITE SPACES COMPLETELY USING OSQL SPOOL?

Thanks in advance for any help.

View 9 Replies View Related

Osql / Isql

Jan 17, 2008

Is osql/isql supported in SQL 2005? How about in 2008? Thanks

View 2 Replies View Related

Osql Timeout

Jul 23, 2005

Hi,I have several big tables with rows more than 25 mil rowsand to update/delete/insert data in these tables,it can take minutes.I use BULK Insert/DELETE/Update with osql.While I run one of these updates,if I try to select, it seems like both read and write get locked.Shouldn't SQL resolve this kind of locking?I left these to see if it gets resolved but both never returned.So I need to kill these processes.Does anyone have any scripts to find how long queries are running?Also I need to make osql timeout and tried -t but it didn't work.I used -t 1200 with DELETE in osql but it was running for more than 40minutes. So I killed it and ran DBCC DBREINDEX on the table and re-ranit and it worked.Shouldn't the query get killed after 10 minutes?What is exactly -t option for ?thanks,

View 2 Replies View Related

Osql Feedback

Jul 23, 2005

I have some long running scripts which I fire at my database using osql.(These are big files and mostly doing inserts but some also do a few otherthings.) It would be nice to have some activity indication (other than thedisk activity light) that these are running. When I used to use Oracle,their equivalent to osql had an option to print a dot (without a carriagereturn) for every "n" statements. This gave a nice "I'm alive" indicator. Ican simulate this by adding a few "print" statements in my sql, but printalways adds a carriage return. Does anyone know a way of doing a print butwithout the addition of a CR (or CR/LF)? So that a second "print" sends itsoutput to the same line as the first?I know this is a nicety and I can live without it, but it would be nice.thanks in advance,Brianwww.cryer.co.uk/brian

View 4 Replies View Related

Using OSQL And DTSRUN

Mar 21, 2006

I have a question. I am doing some work for someone and I have a batchfile that they can run that will execute an OSQL line and a DTSRUNline. In both lines I run them using the /S /U /P switches and ofcourse the /N or /i switch to tell it what to run. I have also triedreplacing the /U /P switches with the /E switch.My problem is that as long as I specify the users password on the OSQLline (either with /U & /P or with /E & /P) it will run. If I try andjust use the /E it will say password failed for DOMAIN/USER . Ok, Idon't really care I can specify the password and the script will run.However no matter what I do the DTSRUN line will not run, it gives methis same password error.I can run this line just fine on my PC on my network and my domainusing just the /S /E switches.Any ideas as to why it will work for OSQL but not DTSRUN?Thanks in advance.

View 5 Replies View Related

Using OSQL For BCP Handling

Feb 1, 2008

I find this thread very useful. But how can I run those scripts in command line using OSQL???

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved