When executing the following batch that is part of a large script:
...
GO
-----------------------------------------------------------------------------------------------
-- Removed the xp_cmdshell for deleting the backup file
-----------------------------------------------------------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PR_MyProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[PR_MyProc]
GO
...
We get the following error on a remote SQL Server:
Msg 121, Level 20, State 0, Line 0 A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)
When we remove "xp_cmdshell" from the comment, the batch succeeds. This error only occurs on some of our SQL servers. We are running the script remotely. The version of SQL Server that fails is:
Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Feb 20 2014 20:04:26 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.2 (X64) (Build 9200: ) (Hypervisor)
On another server the same script succeeds. That server has this version:
Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Feb 20 2014 20:04:26 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (X64) (Build 7601: Service Pack 1) (Hypervisor)
Both servers have xp_cmdshell enabled. The failing server is running Windows 2012 R2 and the server that succeeds is running Windows Server 2008 R2 SP1. If we run the script on the server locally it succeeds. If we run the script remotely from another virtual server, it fails. We also found that the script only fails if the comment has "(space) xp_cmdshell (space)".
Can anyone tell me why this script fails? And why does it fail on some servers and not others?
There is no antivirus running on the server. SQL Server Management Studio is connected, changing the comment to remove xp_cmdshell
always succeeds and the original script always fails.