11

I am trying to map another server by giving the command

EXEC xp_cmdshell 
    'NET USE H:\\568.256.8.358\backup_147 1234abc /USER:cranew /PERSISTENT:yes'

I got an error with this:

network path not found

But I am able to map another server manually. Please help me in sorting this out.

2
  • @Paul-SebastianManole instead of using H:\ , you could just write out the full path, \\server\share\folder\filename.bak. This works perfectly fine for backups, OPENROWSET, etc, provided that you have set up the service account permissions properly. Commented Apr 27, 2017 at 13:35
  • @DanielHutmacher Thank you. In the meantime I've already done this and it works. Indeed, you need to set up three things: the service user account needs to be one that has network access, the same account needs to be a domain account or an account present on the server where the UNC path points to and have the same password, and in my case I had to change file and folder permissions so SQL Server could access the instance database files under the new user account. Commented May 1, 2017 at 21:32

4 Answers 4

8

This is more of a NET USE question than a SSMS/SQL Server question.

NET USE has the syntax:

net use [{DeviceName | *}] 
   [\\\\ComputerName\ShareName[\volume]] [{Password | *}]] 
   [/user:[DomainName\]UserName] [/user:[DottedDomainName\]UserName] 
   [/user: [UserName@DottedDomainName] [/savecred] [/smartcard] 
   [{/delete | /persistent:{yes | no}}]

So, I would expect your command to look like this:

EXEC xp_cmdshell 
    'NET USE H: \\568.256.8.358\backup_147 1234abc /USER:cranew /PERSISTENT:yes'
2

Don't map network drives and expect them to be there. Just backup to the network path directly.

Using mapped drives gets tricky fast as you start to make assumptions that the drive letter will be available next time. What happens when you add another hard drive to the server later and want to use that drive letter? What happens when Windows disconnects the drive to reclaim the network socket?

2

after restart server must execute command plase solution save command...

Use Master
GO

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO

EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
GO

exec xp_cmdshell 'net use  \\ip\xxx pass /user:xxx /persistent:no'

Use Master
GO

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO

EXEC master.dbo.sp_configure 'xp_cmdshell', 0
RECONFIGURE WITH OVERRIDE
0
1

I want to save my backups on an QNAP NAS.

The net use command was ending in error 1312

Solution for me was to just add a ".\" to the username...

exec xp_cmdshell 'net use  \\192.168.0.2\Folder pass /user:.\Peter /persistent:yes'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.