Microsoft KB Archive/296537

= PRB: Sharing Violation Occurs with Operating System Job That Runs Batch File That Echoes Text to Ouput File =

Article ID: 296537

Article Last Modified on 12/3/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 7.0 Standard Edition
 * Microsoft Windows NT Advanced Server 3.1
 * Microsoft Windows NT 4.0
 * Microsoft Windows NT 3.51 Service Pack 5
 * Microsoft Windows NT 3.51 Service Pack 5
 * Microsoft Windows NT 4.0
 * Microsoft Windows NT 4.0 Service Pack 1
 * Microsoft Windows NT 4.0 Service Pack 2
 * Microsoft Windows NT 4.0 Service Pack 3
 * Microsoft Windows NT 4.0 Service Pack 4
 * Microsoft Windows NT 4.0 Service Pack 5
 * Microsoft Windows NT 4.0 Service Pack 6
 * Microsoft Windows NT 4.0 Service Pack 6a

-



This article was previously published under Q296537



SYMPTOMS
When you run a Transact-SQL job by using the xp_cmdshell extended stored procedure or an operating system job to run a batch file that echoes command to an output file, intermittently the output file gets some of the echoes, but then starts displaying the following error message:

The process cannot access the file because it is being used by another process.

Using various monitoring tools, it has been determined that no other process is holding locks on the output file at the time the errors occur.

This problem only occurs on a Microsoft Windows NT 4.0-based computer, with either SQL Server 2000 or SQL Server 7.0. However, the problem does not occur on a Microsoft Windows 2000-based computer.



CAUSE
SQL Agent creates a separate process to run cmdexec job steps or operating system jobs. Before SQL Agent creates the process, SQL Agent also creates a pipe that is used to redirect the standard out of the child process to that pipe. SQL Agent reads from this pipe so as to be able to monitor the output of the child process.

In this case, the child process is calling a batch job that uses echoes with redirection. This redirection is now trying to divert the standard out of the child process into a file. There is likely a timing issue that occurs here, which causes the sharing violations you see in the ouput file. There might be a conflict between reading or writing to the pipe and echoing to a file that may cause this problem.



WORKAROUND
To work around this problem you can either:
 * Upgrade the underlying operating system to Microsoft Windows 2000 from Microsoft Windows NT 4.0. -or-


 * Use an ActiveX scripting language such as Jscript or VBscript instead of using batch files.

Keywords: kbprb KB296537

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.