DOS Batch File Running Osql - Opening/closing Connections

Jul 20, 2007

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


Quote:

View 2 Replies


ADVERTISEMENT

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

Opening And Closing The DB Connection

Mar 16, 2008

Hi most of my code follows the following format in a lot of my pages, my question is; Am i approaching it the right way in terms of performance, sql injection attacks and anything someone more knowledgeable than myself can think off, please feel free to criticise the code. Thank youprotected void Page_Load(object sender, EventArgs e)
{string strID = Request.QueryString["id"];
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["streamConnectionString"].ConnectionString);SqlCommand command = new SqlCommand("stream_EventsByID", conn);
command.CommandType = CommandType.StoredProcedure;command.Parameters.Add("@eventID", SqlDbType.Int).Value = Request.QueryString["id"];
conn.Open();
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
eventList.DataSource = reader;
eventList.DataBind();
conn.Close();
}
}

View 7 Replies View Related

Opening And Closing DB In Different Sub Routiens

Apr 20, 2006

If Someone could please show me some example VB code where i can open the my Sqlconnection in the Page_Load subroutien... and then close that SqlConnection in the Page_Unload routine. I want to be able to execute Sql command without having to re-open and re-close the connection.

Thanks,
Greg

View 4 Replies View Related

Running A SQL File From OSQL Command Line Utility

Jul 20, 2005

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 MSSQLdatabase. Since mysqldump creates the file as raw sql file with thedatabase-table structures and the data in it, I thought using OSQL commandline utilities should work to out this whole database in MSSQL server.I have run this command from command line:osql -u sa -i mysqldump.sqlIt is going since yesterday. It has been almost 36 hours that it'sstarted. And in the mssql server, I see no database created yet. On thescreen of the command line, I see bunch of numbers are going in order. Iassume they are row numbers of the tables processed. But, if it is doing it,then where is it saving all this data ? I have checked the tempdb, pub db,other dbs, and I see no tables related to the database I am inserting. Willit populate it at the and of the job ? Or, am I doing something wrong here?Regards.Murtix.

View 2 Replies View Related

Opening And Closing A Connection In A Loop, Should I Or Shouldn't I?

Oct 31, 2006

i have a loop that can run say 30k times.  in there i am using the try / catch / finally blocks to handle ADO.NET Transactions (thanks CADDRE!)Should i open and close the SQL Connection for each record? or open it and close it outside of the loop only once ?thanks in advance, mcm  

View 3 Replies View Related

Power Pivot :: Determine Opening And Closing Balance

Jun 3, 2015

I am preparing a monthly cash flow statement and for doing so, I need to determine the monthly opening and closing cash balance.  To simplify, this is what I did.

1. Dragged months to the columns labels

2. Created a slicer for selecting the Financial Year.  In this slicer, I chose 2015-16 i.e. April 1, 2015 to March 31, 2016.

Since I have data only for two months of this Financial Year i.e. April and May, only these two months show up in the column labels.

To determine the monthly opening cash balance, I added the following measure

=CLOSINGBALANCEMONTH(SUM(bank_book[Balance]),PREVIOUSMONTH(calendar[Date]))

To determine the monthly closing cash balance, I added the following measure

=CLOSINGBALANCEMONTH(SUM(bank_book[Balance]),calendar[Date])

Much to my surprise, I got the result as seen in the image below.  Cells B5, C6 and D5 are blank.  On going through my Bank Book, I realised that

1. There is no figure in cell B5 (Opening balance of April) because there was no transaction on the last day of March i.e. March 31.  The last transaction was on March 28

2. There is no figure in cell C6 (Closing balance of May) because there was no transaction on the last day of May i.e. May 31.  The last transaction was on May 30

3. There is no figure in cell D5 (Opening balance of June) - same reason as mentioned in point 2 above.

As seen in the image, I have also computed the monthly "Last date of previous month" and "last date of current month" but do not know how to make use of them in computing the opening and closing Cash balances.

Please also note that there can be multiple transactions on the last day of any month.  For e.g., let's say the last day of transaction in May 2015 was May 30 (not may 31) but there were multiple transactions on this last day (both inflow and outflow). 

So I cannot simply determine the last day of transaction and take MAX/MIN/SUM that day.  I have to take the final balance on that day.

How to solve this problem i.e. in determining the opening and closing cash balances.

View 10 Replies View Related

Running A Batch File

Mar 10, 2008

Hi

Is it possible using T-SQL to run a batch file located on different server, ie. PC1 has SQL Server on it, PC2 has the batchfile, I need to run the batchfile stored on PC2 on PC1.

Thanks

View 3 Replies View Related

Running A Batch File

Mar 11, 2008

Hi

I am trying to run a batch file stored on different server from the one that SQL Server is on using T-SQL. I am using the following syntax:

EXEC master..XP_CMDShell '\hit1DEVArchivingArchivingDataFiles.zipdata.bat'

But it doesnt seem to be working, it states that it is not recognised as an internal or external command.

Any ideas?

Thanks

View 1 Replies View Related

Running The Script From A Batch File ( Bcp )

Jun 1, 1999

Exec master..xp_cmdshell "bcp sdnetpro..nbtorder11 out d:databtorder11.txt /c /t /Sservername /Usa /Ppassword"

Hi, this code run fine from within sql server query window. I want to put this code in a batch file and run the batch file.. it did not work. someone told me the revised code is :

bcp sdnetpro..nbtorder11 out d:databtorder11.txt /c /t,/r -Sservername -Usa -Ppassword"

This is not working. Please if anyone knows how to fix this, I would appreciate. One more thing, how can I confirm that the bcp has successfully done. do I have to create a log file and if so what is the code to create this log file.
thanks
Ali

View 1 Replies View Related

Running SQL Query From Batch File- MS SQl 2000

Mar 25, 2008

Hello,
I am looking for some way to run a sql query from a batch file on the SQL server. The query needs a user entered parameter, if that can be accomodated it would be great.
I read about some osql command & tried to run it but it kept saying "Server does not exist or access denied."
Please give me the steps to go about this.
Thanks,
-R

View 4 Replies View Related

Running A Batch File From A Stored Procedure

Jun 27, 2001

Is there a way to run/call a batch file from a stored procedure?

Or, is there a way to run/call a batch file from a trigger?

View 2 Replies View Related

Closing All Connections

Nov 15, 2004

How do I set up a job so that I close all open database connections? I think we have a leak in our code which causes our DB to go down (max connections used) roughly once every month, so we just restart the SQL server. Until we can find the exact problem I'd like to do this.

For simplicities sake let's say my database name is just "test."

Thank you.

View 4 Replies View Related

Connections Not Closing

Feb 23, 1999

I have an app that people frequently disconnect without a logout and the connection remains open in SQL Server. Does anyone know of a script or program that will go through and kill inactive connections?

View 1 Replies View Related

Closing Dts.Connections

Mar 7, 2008



Hello:

I have the following script wrtten in VB that opens a connection to an Analysis Services db in a script task within my control flow:


Dim oConnectionSR As ConnectionManager

oConnectionSR = Dts.Connections("OLAPServer.Sales")


This script is used by a script task within each of three child packages that are called by a parent package. Each call is made to a different OLAP cube. The first package makes the connection and runs fine. When the second package runs, it still sees the connection value from the first package and fails.

What is the best way to close the connection once it is no longer needed? I have tried the dispose() method, and that did not work.

Thanks for your help!

Tim




View 4 Replies View Related

SSIS Package Hangs In Data Flow, Magically Works After Opening And Closing Components

Nov 2, 2006

We're experiencing a problem where intermittently our SSIS packages will hang. There are no log errors or events in the event viewer. It will happen whether the package is executed from the SQL Job Agent or run from BIDs. When running from BIDs it appears to hang inside one of the data flows (several parallel pipes with sorts, merge joins etc...). It appears to hang in multiple pipes within the data flow component. The problem is reproducable, we just kill it and re-run, and it appears to hang in the same places.

Now here's the odd thing: as we simply open and close some of the components in the pipe line after the place it hangs, a subsequent run will go further in the pipeline before hanging. If we open and close all the components after the point it initially hung, the data flow will run fine, from there on out. When I say "open and close" I mean no changes are made, we simply double-click the component, like a merge join, then click 'close.'

To me this does not seem like a memory problem but likely something is wrong with the metadata, where opening a component and closing it somehow alters the metadata to "right it".

This seems to occur intermittently after we make modifications to the package. It's like if you make any mod, even unrelated to the data flow, you then have to go through and open and close every component in your package to ensure it will work. Again, no errors or warnings are fired.

Has anyone seen this type of problem?

View 10 Replies View Related

Problem In Closing Connections

Feb 27, 2008

Hi Guys I am facing a problemI am getting error Timeout
expired. The timeout period elapsed prior to obtaining a connection
from the pool. This may have occurred because all pooled connections
were in use and max pool size was reachedI have checked
my whole code and no Connection leakage is there... but still
Connections are sleeping... I have increse my pool size to 500 and now
i have chaos of 500 sleeping connections... How ever
I have found that even after Opening Enterprize manager i can not kill
Process... How ever my administrator can kill the process from his
enterprize manager... Is there some problem with my credentials or do i need to find  out the leakage  in my code...How ever I have checked twice or thrice  but  my code is Ok and i have  Closed connection properly every where... I am using SQL Server 2000 and ASP.Net 1.1

View 5 Replies View Related

SQL Server 2008 :: Running Batch File To Execute A Stored Procedure

May 11, 2015

I have create a batch file to execute a stored proc to import data.

When I run it from the server (Remote Desktop) it works fine, but if I share the folder and try to run it from my pc, it doesn't do anything. I don't get an error, it just doesn't do anything. My windows user has admin rights in SQL. Why is it not executing from my PC?

View 9 Replies View Related

SQL Server 2000 Not Closing Connections Help!!

Jan 31, 2008



I am experiencing a strange problem on a new installation of SQL Server 2000, installed on Windows 2003 server. SQL server has been service packed to SP3a

The users connect to the SQL database via an MS Access project front end, when they log out of the front end the SQL server still show them as connected in Management > Current activity > process info. I can kill the processes left behind but i am confused as to why this is happening.

The database was recently moved from an SQL installation on a Windows 2000 server to this new Windows 2003 server, the problem didnt occur on the old server and no upgrades have been applied to the database or the front end since the move, which makes me think something is not right about the install.

Any advice would be gratefully received

Thanks
Nick

View 1 Replies View Related

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 Processing Without -i

Jan 17, 2006

Hi,I have just started using MSSQL and the DOS environment at work. I havea lot of experience with Sybase and the UNIX environment, but this is awhole new ball of wax.I'd like to use osql from a batch file to log into the dataserver andrun a fairly long list of SQL and then exit. I don't want to have a bunchof SQL files sitting around that I have to use the -i option to run, andI'd rather not create temporary SQL files like this.echo "exec sp_who2" >tmp.sqlecho "select * from....... " >>tmp.sqlosql -E -S <DATASERVER> -n -w999 -i tmp.sqldel tmp.sqlI can't use the -Q option, of course because as I said, I'll be writingquite a few lines of SQL, and it won't all fit on the one line, or at leastit wouldn't be pretty if I did.In UNIX, I can simply execute the following from either the command lineor ina script.isql -S<DATASERVER> -U<USER> <<-EOFsp_whogoselect * from .....goEOF --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 optionwhich help mentions, and that talks about disabling the EOF terminator forbatch processing, but I wasn't able to find any usage or examples on the netwhere 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 processingAuto console width scalingWide messagesdefault errorlevel is -1 vs 1Any help you could offer would be appreciated. Thanks.Darren

View 2 Replies View Related

Reporting Services :: Get Computed Current Row Closing Balance Column Value In Next Row Opening Value Column

Nov 17, 2015

I have a Table Having Date,Opening,Addition,Sale values where opening value comes in the very first row other times it is zero.

In ssrs how can i have a report showing closing value = Opening+Addition-Sale  in current row (it is simple for 1st row ). this closing be the opening value in next row and same formula to be continued...

Date Opening AdditionTotalTank saleClosing Stock
01-11-15 14435 0 14435 8243 20627
02-11-15 0 15000 15000 9433
03-11-15 0 9000 9000 9436
04-11-15 0 12000 12000 8392
05-11-15 0 6000 6000 8157
06-11-15 0 12000 12000 8456
07-11-15 0 15000 15000 10903
08-11-15 0 6000 6000 8485
09-11-15 0 6000 6000 9413
10-11-15 0 21000 21000 6413

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

Errors Opening ADO Connections Using COM+ Component

Mar 19, 2008

Hello,

We have a strange problem occurring in an environment at a remote client that we're looking into. I was wondering if anybody else has experienced something similar.

We have a COM+ transactional component sitting on a machine that connects to a SQL server machine in the same room (ie no firewall between the two as far as I know, but I'll double check that to make sure).

This component was written in Delphi and uses ADO (sqloledb provider) to connect to the SQL Server. This works 99% of the time. However, there are times where we get the following error when trying to open connection (using the Connection ADO interface):

[DBNETLIB][ConnectionRead (WrapperRead()).]General network error. Check your network documentation

or this:

Connection failure


The error codes associated with these were found in oledb.pas :(-2147467259) $8004D01C and (-2147168228) $80004005

When this happens, it seems to last a few seconds (usually around 10) and then everything comes back to normal. I'm just wondering what could make this happen when the SQL Server seems to be responsive when we try to connect to it using other means. The SQL machine runs Win2k3 sp2 for testing purposes.


Since we were not able to reproduce it yet, I wrote a little application trying to connect to a sql server when it is set on pause. When I run it inside a COM+ transaction, I get the same errors as above right away, the third time I'll get an error telling me that SQL is in pause state, If I run the exact same code but inside a simple vbs application (ie no COM+ transaction), I only get the pause error message sometimes after a few more seconds, and none of the other errors above. Could it be that the COM+ transaction is trying to do other things and these fail so it returns another error? If so, how come after a bit I get the proper message?

Anyways, I'm pretty lost as to why this is happening and how we can try to debug it since we have not been able to reproduce it yet. If anybody has any clues, please let me know.

Many thanks,

Greg

View 3 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

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

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

Stopping/starting Sql Server With Commandlinecommands In Batch To Free Up Idle Connections?

Oct 21, 1999

Hello:

We have a new sales force automation application for sales rep to log their contacts, etc. It runs on mssql 6.5, sp 4.

They log in and leave their connections on without logging off or leave their coonections idle .

We set the user connections fiarly high but we are concerned that the max amount of user connections weill be consumed and the sql serve becomes locked.

My questions are:

1) Is there any parameter in the sql server configuration that will log off idle users have a certain time and dsiconnect them?

2) A backup of the database will be made each night. If there is no parameter, would it be a good idea to stop and start the sql server every night to release the idle connections?

3) If so, how to stop sql server from the commadn and start it with a command line command and do this in a batch file as a scheduled task?

4) Is there any other way to release these idle connections each night?

Any information you can supply will be appreciated. THanks.

David Spaisman

View 1 Replies View Related

Running Batch Files From SQL

Feb 28, 2002

Hi,

I'm trying to run a simple batch file from a SQL job (SQL 7.0 sp4). No errors are received but the job does not complete. When I try to run the job manually, I get a message stating "Error 22022: SQLServerAgent Error: Request to run job my_job (from User DomainAdminUser) refused because the job is already running from a request by Schedule 127 (Schedule 1).

The services are running as a domain admin account.


Help!

Thanks in advance.

View 1 Replies View Related

Running SQL In A Batch Program

Apr 6, 2001

I need to create a program that will run Client Access to download data from the AS400 to a flat file, then run SQL DTS to import the data into a table for use by another software package.

I've created a bat file that does that using the CA RTOPCB command and the SQL DTSRUN utility. Problem is that it appears that I need to first check to see if there is a table in SQL and if there is to delete it. Otherwise, rather than overlay the existing data in the table it adds to it.

Is there a way to issue a SQL drop table in DOS? Or am I missing something that could be done in SQL?

The DTSRUN is using a local package and CA is using a transaction request.

View 1 Replies View Related

Running Batch Scripts

Jun 28, 2006

I've have been sent a large number scritps to update one of the databases i look after. Problem is there are hundreds of individal script files, all of which need to be run.

Is there a script / tool i could use, which would run all of the .sql files in a certain directory and update the database?

I can't seem to find anything built into SQL Server. Job schedular would seem to be the closest thing, but it would still require you select each script needed to be run.

Any ideas would be great.

Thanks
Cj

View 2 Replies View Related







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