473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Output to the log file with XP_CMDSHELL

Hi Folks,

I am using an xp_cmdshell sp to start a C# app. This app downloads
data files and imports them into DB. It has a logging functionality
built-in and when executed from the command line or WE, it records
it's progress into a log TXT file. But when executed via xp_cmdshell,
it doesn't write into its log file.

Is it possible to enable it to write into a log file with xp_cmdshell?
Should I be using a different extended sp to accomplish that?

Any help will be greatly appreciated.

Thank you,
Narine
Jul 20 '05 #1
5 8620
Narine (na************ ***@prurealty.c om) writes:
I am using an xp_cmdshell sp to start a C# app. This app downloads
data files and imports them into DB. It has a logging functionality
built-in and when executed from the command line or WE, it records
it's progress into a log TXT file. But when executed via xp_cmdshell,
it doesn't write into its log file.

Is it possible to enable it to write into a log file with xp_cmdshell?
Should I be using a different extended sp to accomplish that?


Maybe you are looking for the log file in the wrong place? How does the
C# app determine where to write? The current directory when you run
xp_cmdshell is SYSTEM32 on the server machine.

Apart from the logging, does the app do its job?
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2


Thank you for replying, Erland.
C# app works fine, we've had it running as a scheduled task for a while.
The problem is after this app runs successsfully we need to execute a
DTS package. Until now it's been running as two independent processes.
DTS is scheduled to run a little after the app. I wanted to create a
stored procedure that will execute an app and on success execute DTS
package.
This will not only ensure that DTS will run on success but also will
require only one job scheduled.
However, we do need to look at the C# app logs to understand errors
better.
Another alternative would be to write a VB script that will execute the
app then use dtsrun utility to execute the package.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Narine Kostandyan (na************ ***@prurealty.c om) writes:
Thank you for replying, Erland.
C# app works fine, we've had it running as a scheduled task for a while.
The problem is after this app runs successsfully we need to execute a
DTS package. Until now it's been running as two independent processes.
DTS is scheduled to run a little after the app. I wanted to create a
stored procedure that will execute an app and on success execute DTS
package.
This will not only ensure that DTS will run on success but also will
require only one job scheduled.
However, we do need to look at the C# app logs to understand errors
better.
Another alternative would be to write a VB script that will execute the
app then use dtsrun utility to execute the package.


OK, if the C# app runs well, I would assume that is also writing its
logs properly. I mean, if that particular part would fail, the application
would fail too, wouldn't it?

In case it doesn't, write some error-checking where you open the log file,
and print an error message to standard output - this would become a result
set from xp_cmdshell.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4
An executable can be a job step. The only trick is that you have to
make it finish with a return value that Agent can understand as
success or failure.

On 28 Apr 2004 23:56:53 GMT, Narine Kostandyan
<na************ ***@prurealty.c om> wrote:


Thank you for replying, Erland.
C# app works fine, we've had it running as a scheduled task for a while.
The problem is after this app runs successsfully we need to execute a
DTS package. Until now it's been running as two independent processes.
DTS is scheduled to run a little after the app. I wanted to create a
stored procedure that will execute an app and on success execute DTS
package.
This will not only ensure that DTS will run on success but also will
require only one job scheduled.
However, we do need to look at the C# app logs to understand errors
better.
Another alternative would be to write a VB script that will execute the
app then use dtsrun utility to execute the package.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 20 '05 #5
kgard
1 New Member
I'm having the same problem. I have a C# console app that returns a 0 for success and a 1 for failure. Even though it returns a 1 and displays the error in the output, it still displays NULL in the return code output. How can I get the return value generated from the C# executable to be assigned to this return value in SQL. Also, even upon failure, the job will still display that it was executed successfully. Please help.

thanks.
Jun 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8806
by: Ryan | last post by:
I have a table in my database on SQL Server which holds a file name that refers to a file that is stored on the server. I would like to create a trigger to delete this file from the server if the row in the table is deleted. I have been trying to use this command in a trigger (<filename> is the name and path of the file): xp_cmdshell "delete <filename>" If some one could please help I would appreciate it very much. I would love a...
1
33301
by: Dan Bart | last post by:
I need to execute xp_cmdshell in a trigger and pass a command line parameter to the .exe program i.e. I have a .exe program c:\program files\savedata.exe In the trigger I have a parameter @Id bigint I need to pass the parameter @Id to savedata.exe In the trigger, I am trying
4
8095
by: Joel Thornton | last post by:
Whenever something is inserted to a given table, I want to run some shell commands using xp_cmdshell. Would it be a bad idea to put this xp_cmdshell in the INSERT trigger of this table? I understand that when using xp_cmdshell, the sql thread in question waits until xp_cmdshell finishes what it's doing. Does this mean if my xp_cmdshell call takes 30 seconds, that nobody else can insert to this table until my xp_cmdshell and rest of the...
4
2283
by: Narine | last post by:
Hi Folks, I am using an xp_cmdshell sp to start a C# app. This app downloads data files and imports them into DB. It has a logging functionality built-in and when executed from the command line or WE, it records it's progress into a log TXT file. But when executed via xp_cmdshell, it doesn't write into its log file. Is it possible to enable it to write into a log file with xp_cmdshell? Should I be using a different extended sp to...
10
149119
by: Alex | last post by:
Hi, How would I go about writing the results of an SQL query to a text file? I cannot find any info in the Online help files. For example, I would like the results of: SELECT * FROM TableA
2
2301
by: cpeters5 | last post by:
Deaa group, I am using SQLServer 2000 in an XP Sp2. I would like to do the following: I have a program running on a database server that generates some data which are loaded to the database. This program is used in a web application, invoked by some java program and JSP scripts. (I am frontend illiterated.)
3
7490
by: phantom | last post by:
Greetings, I have a sp that dumps text into a textfile but I am having trouble creating the textfile. EXEC master.dbo.xp_cmdShell '\\servername\d$\The File\sub\filename.dat' The directory "The File" has a space in it. I've tried putting the carat ^ before the space, and putting double quotes...but I keep getting this error
0
2289
by: mcolson | last post by:
I am trying to execute a batch file using xp_cmdshell: EXEC xp_cmdshell 'c:\testing\runbattest.bat' When I do this, I get an output that says "Access is denied." Here are the contents of my batch file. dir c:\windows\*.exe c: \test.txt The batch file works fine, but I can not run it from sql. It should be noted that I am using SQL Server Express. Do I need the full blown
7
4467
by: FutureShock | last post by:
I have been using SQL Server 2005 for a total of 2 days and am trying to transfer table data from one server to another. For whatever reason the original operator only gave us the DB in a BAK file. The new server for security purpose won't accept that for a restore unless it was made on their server. I installed 2005 express and was able to restore on my computer. I was then able to brute force recover the table 'structure' on the new...
0
9554
marktang
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...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5266
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...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.