xp_cmdshell strange problem

I was working on this request: from a ship are unloaded many containers, it is needed to track the ones not still invoiced; in this case must be sent an email with an Excel file as attachment, containing the list of these containers.
The containers are register in a table of an SQL Server 2008 SP3 10.0.5520.0 (X64).
I tried OPENQUERY but without success (it seems that read and write Excel with OPENQUERY is a sort of black magic) so , giving also the fact that in every case there were many steps too complex to achieve with TSQL (CreateObject and CLR stored procedures were not acceptable options) i used an SSIS package , without using a SSIS catalog: it must be used dtexec.
I shoud try with SQL Server 2014, but with SQL 2008 there is this problem and double quoted strings are tipically requested in a dtexec command line: so i use the trick of the old MSDOS command ECHO to create a batch file and then execute this .bat from xp_cmdshell.
My TSQL is :

DECLARE @varSql nvarchar(500)
DECLARE @varFileName nvarchar(20)
DECLARE @varEcho nvarchar(1000)
DECLARE @XlsFileName nvarchar(500) 
DECLARE @intRes int
SET @varFileName = 'D:\SSIS\ContainersWithoutBilling\batches\' + CAST(@p_Voyage AS varchar) + '.bat'
SET @XlsFileName = 'D:\SSIS\ContainersWithoutBilling\Voyages\' + CAST(@p_Voyage AS varchar) + '_NotInvoiced.xlsx'
SET @varSql = '' + CHAR(34) + 'C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\dtexec' + CHAR(34) + ' /FILE ' + CHAR(34) + 
				'D:\SSIS\ContainersWithoutBilling\SSISPkg\bin\Package.dtsx' + CHAR(34) + ' /CHECKPOINTING OFF  /REPORTING EW  /SET \Package.Variables[IDVoyage].Value;' + 
				CAST(@p_Voyage AS varchar)
SELECT @varEcho = 'ECHO ' + @varSql  + ' > ' + @varFileName 
EXEC @intRes =  master..xp_cmdshell @varEcho , no_output	

At this point we have an batch file, for example is generated something as this 116243.bat:

"C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\dtexec" /FILE "D:\SSIS\ContainersWithoutBilling\SSISPkg\bin\Package.dtsx" /CHECKPOINTING OFF  /REPORTING EW  /SET \Package.Variables[IDVoyage].Value;116243

This example works without problems launched from the File Explorer, and you can think that with

EXEC @intRes = master..xp_cmdshell @varFileName, no_output

your problems are resolved, instead i was surprised that sometimes the .bat file, that was perfectly working launched by hand, under xp_cmdshell the process hangs: and i was constrained to kill both the cmd and the dtexec processes.
Tipically a xp_cmdshell is blocked if is requested an user input , but this was not the case.
After some head scratching, i tried with an temporary job:

DECLARE @jobID uniqueidentifier
DECLARE @cmd varchar(1000) 
SET @cmd = 'D:\SSIS\ContainersWithoutBilling\batches\' + CAST(@p_Voyage AS varchar) + '.bat'
EXEC msdb.dbo.sp_add_job @job_name = '_tmp_batch', @enabled  = 1, @start_step_id = 1, @owner_login_name='sa', @job_id = @jobID OUTPUT 
EXEC msdb.dbo.sp_add_jobstep @job_id = @jobID, @step_name = 'launch batch', @step_id = 1, @subsystem = 'CMDEXEC', @command = @cmd
EXEC msdb.dbo.sp_add_jobserver @job_id = @jobID
EXEC msdb.dbo.sp_start_job @job_id = @jobID, @output_flag = 0 
WAITFOR DELAY '00:00:30' -- wait an reasonable time of 30 seconds until the job should be securely completed
IF EXISTS (SELECT name FROM msdb.dbo.sysjobs WHERE name = '_tmp_batch')
	EXEC msdb.dbo.sp_delete_job @job_name = '_tmp_batch'
-- or you could delete if exists the temp job before the creation, and avoid the
-- WAITFOR if there are not other instructions that depends from the job work

and this is working also for the .bat files that hangs under xp_xmdshell.
I think that using an SSIS catalog there aren’t these problems, but in this case the dtexec was mandatory.
At the end it seems that xp_cmdshell has some bug, and an temporary job is always a better choice.

Categories: SQL Server, SSIS

20 years ago

It was the day of Windows 95 (24 August 1995..do you remember “start me up” of the Rolling Stones?)
After the dark ages of the File Manager we got the Start button, long file names, and so on.
.NET was not even to the horizon, COM was the leading technology , 4mb was the standard pc memory instead of 4gb but Windows 10 is still using some proof of concepts of his great-grandfather.

Categories: Uncategorized

Error creating an Azure Cloud Service with 2.7 SDK

From some days is available the Azure 2.7 SDK, and i’m trying it with Visual Studio 2013: when Visual Studio was alerting that were available this update i installed it from inside Visual Studio.
Creating an Azure Cloud Service i got the error “Microsoft Azure Tools: Error: The installed Microsoft Azure Compute Emulator does not support the role binaries. Please install the latest Microsoft Azure Compute Emulator and try again.”.
I don’t know if is the real solution valid for all the cases, but anyway re-downloading the Microsoft Azure SDK for .NET – 2.7  from http://www.microsoft.com/en-us/download/details.aspx?id=48178 but installing only the MicrosoftAzureComputeEmulator-x64.exe (x86 if you are using an 32 bit environment, but who has today an 32 bit pc?) finally the project has started.

Categories: .NET, Azure, Visual Studio 2013

10 days with 10

On 29 July i tried to update my Windows 8.1 to Windows 10, downloading the ISO from MAPS.

It took from 13:00 to 17:30, on my HP Pavilion: i think that the long time is due to Office 2013, Visual Studio 2013 and others installed software.
This is the initial phase:

After 10 days the impressions are:
– less ugly than Windows 8.1: is less bidimensional/two colors only
07-08-2015 21-58-38
– faster, even if is sometimes difficult to say where ends the real advantage and begins the placebo effect: in every case it seems that there is a better use of threading.
– Edge: very valid, fast; i tried many sites without problems.
– Cortana: in a normal notebook, used with the mouse, is not of interest.
– I’m still not satisfied with the Windows Search: why i can’t have a true details view of the search results, with sortable columns? in the past it was possible.. if there is this possibility, is well hidden.
“This Pc” instead of “Computer” was the first problem… but after 10 minutes i was already confident with the new Windows.
After the installation the c: drive could be filled to the limit, because is created a folder for the old Windows, but i think that no one will desire the old 8.1: this article explains how to free up disk space.
The network icon on the taskbar is gone and the network settings are not simple to found at a first sight, and i don’t understand the ugly B/W look of the “Settings” when the Control Panel seems the Windows 7 old counterpart.
I’m an VmWare Workstation (currently 11.1.2) user, and on the same pc upgraded from 8.1 to 10 the “Unity mode” is more fluid with 10, the windows moved on another screen are working in a more fluid manner.
Generally speaking you can sense an “work in progress” feeling, but this first initial version is already good.

Categories: Uncategorized

Hacked cars

In this my old post i was in some manner seeing the future.
Now i’m reading this article: Marchionne, are you aware?
We will see an Cisco firewall inside our car dashboard?
Anyway the problem is very hot: with my old 80’s cars (an awful sample..) there weren’t these problems..

Categories: Uncategorized

New record

running at 60 km/h, same road with some trees, 18:30

Categories: Uncategorized


No, not Saudi Arabia, but northern Italy..and no, the car was not leaved in a parking exposed to the sun: the temperature was encountered along the road.
17-07-2015 15-34-59

Categories: Uncategorized

Eclipse Luna memory problem

Some weeks ago i fought a battle with Eclipse.
I made updates to my PlaceMinder project , updating the Android SDK and some code changes.
The project was working before, now trying to launch on the device (anyone was ever able to get the emulator working?…) errors about “heap space” and “out of memory”.
I was not understanding , because another project even more complex, in another workspace, was working after the SDK updates.
The solution was to modify the eclipse.ini, by changing the last lines from the default values to:


And my app was finally installed on the device.

Categories: Android

Angular modal problem after update

I was already prepared to the head banging.
I had a .NET 4.5 project with Angular 1.3.15, reopening for some update i tried an NuGet update and voilà, Angular 1.4.1 available: but no updates for Bootstrap, still 3.3.4 … troubles to the horizon…
The site is essentially an employees management, with add update delete done using modal windows.
After the update apparently all still working until i tried an update (of a record).
The original code was

modalInstance = $modal.open({
    templateUrl: 'app/partials/formemployees.html',
    controller: 'modalController',
    backdrop: "static",
    keyboard: true,
    modalFade: true,
    scope: $scope

With this code the modal window was appearing, inside the window no problem for fields editing, but after closing the window by the ESC on the keyboard or the Save button, on the browser canvas a grey background was covering everything: only after an F5 the site was working.
The problem seems related to the BootStrap version not aligned to Angular for the “modal” part; after some struggle i found that the problem is relative to the animation feature.
By adding the clause “animation: false, ” :

modalInstance = $modal.open({
    animation: false,
    templateUrl: 'app/partials/formemployees.html',
    controller: 'modalController',
    backdrop: "static",
    keyboard: true,
    modalFade: true,
    scope: $scope

Now the modal is working correctly.


Get every new post delivered to your Inbox.