The first thing to do was to create a mapped drive using the "NET USE" command with a Execute process task:
I had to change the first 3 properties of the task:
- RequireFullFileName: False
- Executable: cmd.exe
- Arguments: /c "NET USE Z: \\192.168.1.10\sqlbackup /USER:username password /p:NO"
The /p:NO at the end means that the mapping will not be persistent. This is optional.
Next step was to change the destination connections to use the new mapped drive:
Also set the DelayValidation to True for this, otherwise you will get an error because the drive has not been yet mapped.
In the end, the package would look like this:
In the last Execute process task I remove the drive with the command: /c "NET USE Z: /delete":
However, when I tried to run the package, I always got the following error message:
The specified network password is not correct.
I was not getting this error in the package execution error, but when I was trying to run the command manually.
I was running this on a Windows Server 2012, 2008 and 2008 R2 machines and there was still something left to do:
- Start -> run -> secpol.msc
- Local Policies -> Security Options -> Network Security: LAN Manager Authentication level
- Change to Send LM & NTLM - use NTLMv2 session security if negociated
The problem with SQL Server Agent
Although the package runs fine in BIDS I was not able to run the package from a job in SQL Server Agent. The package was not deployed to SQL Server.
The only way I was able to run it from the Agent was to create a batch file (.bat) with the command "C:\Windows\System32\net.exe USE Z: \\192.168.1.10\sqlbackup /USER:username password" and change the Execute Process Task to run the batch file:
I need to pass the sourcelocatio, username and password as variables too. Can anyone help on how to do that
ReplyDelete