Batchfile Calling SQLCMD To Call A SQL Server Agent Job

Jan 15, 2008





Hi All,



You have to forgive me but I am relatively new to this. I created a batch file which would call a SQL Server Agent Job. The said job calls SSIS packages. The last step for the job was to update a table which contains the next run date for the job. The batch file, after calling the job, would then query the table where the next run date is stored and place it in a log file. However, it seems that the log file gets updated first. The user who clicked on my batch file assumes that the job is finished and would proceed to run another program which scans all the records affected by the job. Since the job is not yet finished, the few records that were affected are the ones that are only scanned leaving the other records that are yet to be transferred.



Does calling SQLCMD from a batch file spawn a new thread for the job?



Why does the date get updated even though the job is not finished yet?



I have attached the bat file I created. Below that also is the control flow

@echo off
echo.
echo Executing job PRD_ICBS...
echo.
echo Please wait...
SQLCMD -Q "EXEC msdb.dbo.sp_start_job @job_name='TRANSFER_DATA'"
echo.
echo Creating folder %date:~-4,4%-%date:~-10,2%-%date:~-7,2%...
md %date:~-4,4%-%date:~-10,2%-%date:~-7,2%
cd %date:~-4,4%-%date:~-10,2%-%date:~-7,2%
date/t >> TRANSFER_DATA.txt
echo PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_TD >> PRD_ICBS.txt
echo PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_CASA >> PRD_ICBS.txt
echo PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_LOANS >> PRD_ICBS.txt
SQLCMD -Q "SELECT next_rundate FROM db.NEXT_RUNDATE_PARAM WHERE NAME = 'PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_TD'" -o "PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_TD.txt"

SQLCMD -Q "SELECT next_rundate FROM db.NEXT_RUNDATE_PARAM WHERE NAME = 'PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_CASA'" -o "PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_CASA.txt"

SQLCMD -Q "SELECT next_rundate FROM db.NEXT_RUNDATE_PARAM WHERE NAME = 'PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_LOANS'" -o "PRD_Insert_HMTRANSACTIONDATADETAILS_From_ICBS_LOANS.txt"


----------------------------- ----------------------------------------
| | | |
| Transfer Data | ===> | Update NEXT RUN DATE | |
| | | |
----------------------------- ----------------------------------------


Thanks in advance

View 7 Replies


ADVERTISEMENT

Calling SQLCMD From Within An Executing Procedure

Apr 4, 2008

Is there a way to call SQLCMD from within an executing procedure?

View 3 Replies View Related

Calling SQL Server Agent JOB From A SSIS Package

Feb 9, 2007

Hello

do ne one know how to call a SQL SERVER agent job from a SSIS package?

regards,

Anas

View 1 Replies View Related

SQL Tools :: Server Agent - Remote Procedure Call Failed (0x800706be)

Jun 20, 2011

I can't access SQL Server 2008 R2 remotely on Windows 2008

1.  TCP/IP Enabled for SQL Server Network Configuration Protocols, SQL Native Client 10.0 configuration clients, and SQL Native Client 10.0 configuration clients(32 bit)

2.  Firewall disabled to make sure its not interferring with things.

I noticed the SQL Server Agent is Stopped.  Not sure if this is the issue.  When I try and turn this from disabled to Automatic or Manual, I get this error:

Remote procedure call failed (0x800706be)

It shouldn't be this difficult.

View 23 Replies View Related

Invoke SSIS From Client-side Batchfile

Oct 9, 2007

Until now we worked with SQL Server 7.0, now we're migrating to SQL Server 2005.

With SQL Server 7.0 we had an MS Access application (located on a file server) used by several users, from which's form a batchfile (located on the same server) can be started. The Batchfile deletes an existing TXT-file called import_result.txt, then invokes a DTS-Package (located on a SQL Database server) which imports data to the Access-DB and creates a new file with the result of the DTS-execution (again called import_result.txt). Like that the user gets some information about success (or failure) of the data import.

How could this be implemented with SQL Server 2005 without having to install (and to licencse) SQL Express Engine on the clients? I found some threads about how to invoke an SQL Agent Job from the client to execute the SSIS-Package on the server, but I think that's not exactly what we need. Besides I'm not quite sure how exactly the SQL Agent Job could be invoked from Access.

Do you have any proposals?
Meicee

View 5 Replies View Related

SSIS Called From Agent Job Not Calling New Child SSIS Package Addition

Oct 29, 2007

I have an SSIS package (TransAgentMaster) that I recently modified to include a call to a child package via the file system. The child package creates a text file. When I run the package in dev studio then the child package/text file is produced.

I then imported the TransAgentMaster as a stored packagesfilesystem package into SQL SSIS and executed the package. The child package produced the text file.

I then ran the SQL Server Agent to see if the child package would work and it did not generate the text file. Thus after updating a SSIS package importing the package into SSIS the job that calls the package will not call the child package. Please not that the TransAgentMaster package calls 7 children packages €¦ just not my new one.


Any thoughts why the agent will not run the child newly crated childe package?

View 3 Replies View Related

Execute Sql Server Agent Job Task - Job Immediately Returns Success... However Agent Job Is Still Running???

Nov 30, 2006

when I run a package from a command window using dtexec, the job immediately says success.
DTExec: The package execution returned DTSER_SUCCESS (0).
Started: 3:37:41 PM
Finished: 3:37:43 PM
Elapsed: 2.719 seconds



However the Job is still in th agent and the status is executing. The implications of this are not good. Is this how the sql server agent job task is supposed to work by design.



Thanks,

Larry

View 1 Replies View Related

Can Sqlcmd Be Used On A SQL Server 2000 Box?

Feb 7, 2008

I have a SQL server 2000 box. I saw a post some time ago in MSDN Forums that the sqlcmd utility could be used on SQL Server 2000 as well. However, when I tried to install sqlcmd using file SQLServer2005_SQLCMD.msi downloaded from Microsoft, I got following error:


Setup is missing prerequisites:- SQL Native Client

Does this mean that I need to install SQL 2005 Client? How do I make sqlcmd work on a SQL Server 2005 box?

Please advise. Thanks.

Jim

View 3 Replies View Related

How Do I Install Sqlcmd.exe In My SQL Server Client

Nov 14, 2006

I have SQL Server 2000 client installed in my machine and I need to call stored procedures thru sqlcmd utility. When I tried using this utility, I got an error message from command prompt sqlcmd command does not exist.

I have osql utility in my client version, but i need to have sqlcmd utility.



Please advice how do I install sqlcmd.exe in my SQL Server client?

View 1 Replies View Related

Unable To Connect To Sql Server Express Using SQLCMD

Aug 15, 2006

Hello,

I'm unable to connect to Sql Server express using SQLCMD. I've trawled through countless web pages to try to solve my problem but to no avail.

Using windows 2000.

I'm getting the message:

HResult 0x2, Level 16, State 1

Named Pipes Provider: Could not open a coonection to SQL Server...............

Sqlcmd: Error: Microsoft SQL Native Client : Login timout expired.

I've enabled the various protocols in the Sql config manager......



Please help!



Thanks,



dom

View 7 Replies View Related

SQL Server Agent Could Not Access Replication Agent

Feb 19, 2007

We just moved source server to newer, bigger box ... Windows 2003 and Active Directory ... Snapshot agent worked but distribution failed ... Same login as on older machine, login is sysadm, used DCOMCNFG to allow ability to launch process ... What are we missing?

View 4 Replies View Related

Sqlcmd And Osql Error HResult 0x2 SQL Server 2005 Exp

May 16, 2007

Hello,

I get following error trying to use SQLCMD OR OSQL

Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi
shing a connection to the server. When connecting to SQL Server 2005, this failu
re may be caused by the fact that under the default settings SQL Server does not
allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

I searched this forum for answers and I found one solution where it was said that Remote connections for TCP and Named Pipes needs to be enabled. I have them enabled, but I still get this error. I had working SQL server before, but I had to uninstall it. Now after installing ti again I started to get this error.

Anything else besides disabled remote connections cause this problem? I'm trying a local connection. I heard elsewhere that this could be firewall related, but shouldn't it use local connection always when I try to connect it with sqlcmd and no other parameters given?

View 2 Replies View Related

Error 2755 Installing SQL Server 2005 SQLCMD

Dec 17, 2007

I get this error trying to upgrade my SQLCMD package:

"The installer encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2755"

I've seen other threads addressing this but not for the SQLCMD installer. They suggested either not having write permission or not running from the local C: drive. I'm an Administrator on the system and the package is on the C: drive. So, what else? Thanks.
-- Ian

View 1 Replies View Related

I Just Want One Entry For Each Call, With SLA Status 'Breach' If Any Of The Stages For The Call Were Out Of SLA.

Mar 19, 2008

Hi,

I am producing a php report using SQL queries to show the SLA status of our calls. Each call has response, fix & completion targets. If any of these targets are breached, the whole SLA status is set as 'Breach'.

The results table should look like the one below:





CallRef.

Description

Severity



ProblemRef

Logged
Date

Call
Status

SLA Status



C0001

Approval for PO€™s not received

2



DGE0014

05-01-06 14:48

Resolved

Breach


C0002

PO€™s not published

2



DGE0014

06-01-06 10:21

Resolved

OK


C0003

Approval for PO€™s not received from Siebel.

2



n/a

05-01-06 14:48

Investigating

OK



















Whereas I can pick the results for the first 6 columns from my Select query, the 'SLA Status' column requires the following calculation:

if (due_date < completed_date)
{ sla_status = 'OK';
}
else sla_status = 'Breach';

The Select statement in my query is looking like this...

Select Distinct CallRef, Description, Severity, ProblemRef, Logdate, Status, Due_date, Completed_date;

The problem is that my query is returning multiple entries for each stage of the call (see below), whereas I just want one entry for each call, with SLA status 'Breach' if any of the stages for the call were out of SLA.






CallRef.

Description

Severity



ProblemRef

Logged
Date

Call
Status

SLA Status



C0001

Approval for PO€™s not received

2



DGE0014

05-01-06 14:48

Resolved

Breach


C0001

Approval for PO€™s not received

2



DGE0014

05-01-06 14:48

Resolved

OK


C0001

Approval for PO€™s not received

2



DGE0014

05-01-06 14:48

Resolved

Breach



















Any help will be much much appreciated, this issue has been bothering me for some time now!!!




View 7 Replies View Related

Management Studio Express &&amp; SQLcmd: Syntax Errors In Executing A MS-DOS Batch File &&amp; A Microsoft SQL Server Query File?

Nov 2, 2007

Hi all,
I have the "Northwind" database in my Sql Server Management Studio Express.

In my C:ProSSEAppsSamplesForChapter02Chapter02 folder, I have the following 2 files:
(1) ListColumnValues (MS-DOS Batch File)
sqlcmd -S .sqlexpress -v DBName = "Northwind" CName = "CompanyName" TName =
"Shippers" -i c:prosseappschapter02ListListColumnVales.sql -o
c:prosseappschapter02ColumnValuesOut.rpt
(2) ListColumnValues (Microsoft SQL Server Query File)
USE $(Northwind)
GO
SELECT $(CompanyName) FROM $(Shippers)
GO
When I ran the following SQLcmd:
C:ProSSEAppsSamplesForChapter02Chapter02>ListColumnValues.bat
I got the following "ColumnValuesOut.rpt" with error messages:

'Northwind' scripting variable not defined.
Msg 102, Level 15, State 1, Server L1P2P3SQLEXPRESS, Line 1
Incorrect syntax near '$'.
'CompanyName' scripting variable not defined.
'Shippers' scripting variable not defined.
Msg 102, Level 15, State 1, Server L1P2P3SQLEXPRESS, Line 1
Incorrect syntax near 'CompanyName'.

I copied these T-SQL statements from a book and I do not know how to correct them.
Please help and tell me how to correct these errors.

Thanks in advance,
Scott Chang




View 3 Replies View Related

SQL Server 2005, SQL Server Mobile, SQL Server Management Studio. Unsupported HTTP Function Call

Sep 5, 2005

Hi All,

View 14 Replies View Related

A Call To SQL Server Reconciler Failed. SQL Server 2005, SQL Server Mobile Merge Replication

Oct 2, 2005

Hi,

View 36 Replies View Related

SQL Server 2008 :: Restoring A Database / Server Using A Remote Server As The Service Call?

Jan 4, 2013

if you can restore a database to Server B using Server A as the service. Meaning we would issue the command on Server A but somehow point to Server B as where we want the restore to happen.

The backup file would be in a location independent of both servers.

View 4 Replies View Related

SQLCMD

May 4, 2007

I cannot get SQLCMD to run. When I run it, it appears for a few seconds then dissappears. I tried running it in cmd and it says it cannot run because the default setting for SQL server does not allow remote connections. Please help.

View 11 Replies View Related

SQLCMD

May 2, 2008

When connecting to SQL using the SQLCMD
Is there a way to do a select and it output in DOS mode...

Even have the message return - completed just as if you were in sql query.

View 1 Replies View Related

SQLCMD

May 22, 2008



Hello,

Does anyone know how to execute a stored procedure in a SQLCMD script? Here is what I have so far and it doesn't seem to be working...

:r $(rootPath)"Script.sql"
GO
exec sp_Proc
GO


Also,

Is there a way that I can pass the $(rootpath) as a parameter in my stored proc?

Thanks!

View 3 Replies View Related

SQLCMD.exe

Feb 21, 2008



I am trying to backup/restore a sql db using sqlcmd. My question is, the box that I am trying to run sqlcmd on does not have SQL server 2005 installed, can I just copy SQLCMD.exe to the box instead of Installing it? if so, are there any other files that I need to copy as well?

I have another instance where I was trying to backup/restore a 2000 sql db and all I did was copy the osql.exe and resource files to the box and was able to run this command with out installing SQL server 2000. So, did something change with SQL serve 2005?

Thanks for any suggestions

View 6 Replies View Related

Need Example -- SQLCMD -y

Aug 23, 2006

Hi,

Please can any one let me know jhow to use -y option with SQLCMD.







View 11 Replies View Related

SQL Server 2014 :: Call For DB Backup For A Database On Another (linked) Server

Jul 8, 2015

I have a sproc that will generate a dynamic call (and this must be done in a stored procedure),... Anyway the dynamic call I am having problems with is that I need to dynamically create a statement to backup a database. It works as long as the database is on the same server / instance as the stored procedure. I want to be able to from server/instance A create a command that does a backup of a database that is on server B. I just can't figure out the syntax for a database backup where the database is on another server.

Trying something like [ServerName].[DatabaseName] does not work...

View 9 Replies View Related

Calling Dll`s/exe`s From SQL Server

Oct 5, 1998

I need a simple example of calling a dll or exe with params
from a stored procedure.

Thanks
Robert Kapciuk

View 1 Replies View Related

Calling Sp From DTS On Different Server

Sep 16, 2004

Is it possibe to call a Stored Proc on a remote server in a DTS package?

Thanks in advance,

John

View 3 Replies View Related

Sqlcmd Syntax

Jul 20, 2007

How can I use sqlcmd to execute a simple stored procedure, I dont need to pass parameters in or out, its just for backups.

Thanks

View 2 Replies View Related

Sqlcmd Question

Mar 3, 2008

Greetings all!

i am using the follownig sqlcmd command to output some data :

sqlcmd -E -S myServermyInstance -s "," -W -d myDB -Q " set nocount on select ltrim('""' + cast(PersonId as varchar) +
'-' + cast(DatabaseId as varchar) + '""') as 'URN-DBID','""' + EmailAddress + '""' as EmailAddress from myDB.dbo.myTable where
DTS > dateadd(dd, -7, getdate()) set nocount off " > "\tfsvrCompanyDatabase DevelopmentTestReports"myRecords-20080303.txt

The output looks something like this :

URN-DBID,EmailAddress
--------,------------
"5-1","blahblah@HOTMAIL.COM"
"264541-1","blahblah@HOTMAIL.COM"
"1107457-1","blahblah@HOTMAIL.COM"
"6133752-1","blahblah@HOTMAIL.COM"

Is it possible to keep the headnigs but remove the dashed line?

Your help would be much appreciated.

View 5 Replies View Related

Sqlcmd Question

Mar 3, 2008

Greetings all!

i am using the follownig sqlcmd command to output some data :


sqlcmd -E -S myServermyInstance -s "," -W -d myDB -Q " set nocount on select ltrim('""' + cast(PersonId as varchar) +
'-' + cast(DatabaseId as varchar) + '""') as 'URN-DBID','""' + EmailAddress + '""' as EmailAddress from myDB.dbo.myTable where
DTS > dateadd(dd, -7, getdate()) set nocount off " > "\mynetworkdrivemyCompanymyDatabase DevelopmentmyTestReports"myRecords-20080303.txt


The output looks something like this :

URN-DBID,EmailAddress
--------,------------
"5-1","blahblah@HOTMAIL.COM"
"264541-1","blahblah@HOTMAIL.COM"
"1107457-1","blahblah@HOTMAIL.COM"
"6133752-1","blahblah@HOTMAIL.COM"

Is it possible to keep the headnigs but remove the dashed line?


Your help would be much appreciated.

View 4 Replies View Related

Sqlcmd - View

Mar 21, 2006

how can i change the view in sqlcmd?

such as changing the font or the window size so that a command such as sp_tables will list on one row rather than several. Also I would only like to see 10 records or so at the same time. Currently in default setting, if i run sp_tables I can really only view the last few records.

thanks!

View 1 Replies View Related

What Is The Alternative To Go Under Sqlcmd?

Oct 8, 2006

Hi

I found it a bit annoying to type Go after some very simple query and I wonder is there a short cut to execute the query i type right after I press enter?

1> select * from Table
2> go <enter>

instead, how to you execute line 1 without entering go?

Thank you

View 7 Replies View Related

Backups From SQLcmd ??

Nov 9, 2006

I am working with SQL Express and found myself surprised when I tried to automate a backup... No Agent.

So I am trying to create a simple backup script to run from the command line and probably schedule through the scheduled task manager.

here is my problem. I get the following error :

Msg 2812, Level 16, State 62, Server FIREFLYSQLEXPRESS, Line 1
Could not find stored procedure 'B'.

Here is the batch file

sqlcmd -i c: emp estDBbackup.sql -o c: emp estoutput.txt -S FIREFLYSQLEXPRESS

And here is the sql input file :

BACKUP DATABASE [DNNDEV] TO DISK = 'C: emp estdnndev.bak' WITH NOFORMAT, NOINIT, NAME = 'dnndev-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10;

If I put a USE statement in front of my backup statement - the error message changes to

Could not find stored procedure 'U'.

So it would appear to list the first character encountered.

As a sanity check I created a similar process which does a select * from a table and I do not get an error saying :Could not find stored procedure 'S'. - instead all is well and I get my output and no error

If I try the backup command in SQLCMD interactively it works.

so what the heck am I missing ?

Thank you for any help...

View 4 Replies View Related

SQLCMD Error

Apr 14, 2008

Dear profetionlas:
I cannot run sqlcmd in my computer but i can connect to my SQL Server2005 through SSIS
This is the error I see .
Please give me some recommandation


C:Documents and Settings est>sqlcmd
HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi
shing a connection to the server. When connecting to SQL Server 2005, this failu
re may be caused by the fact that under the default settings SQL Server does not
allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.


I would like also metion that
1)windows firewall is off
2)All SQL server Services are running
3)This is my default instance also I have another named instance in the server

View 4 Replies View Related







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