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



The information in this article applies to:

  • Microsoft SQL Server 2000 (all editions)
  • Microsoft SQL Server 7.0
  • the operating system: Microsoft Windows NT 3.1
  • the operating system: Microsoft Windows NT 3.5
  • the operating system: Microsoft Windows NT 3.51
  • the operating system: Microsoft Windows NT 3.51 SP5
  • the operating system: Microsoft Windows NT 4.0
  • the operating system: Microsoft Windows NT 4.0 SP1
  • the operating system: Microsoft Windows NT 4.0 SP2
  • the operating system: Microsoft Windows NT 4.0 SP3
  • the operating system: Microsoft Windows NT 4.0 SP4
  • the operating system: Microsoft Windows NT 4.0 SP5
  • the operating system: Microsoft Windows NT 4.0 SP6
  • the operating system: Microsoft Windows NT 4.0 SP6a

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.

Modification Type:MajorLast Reviewed:12/3/2003
Keywords:kbprb KB296537