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.

Paul White
  • 94,921
  • 30
  • 437
  • 687
Anto
  • 643
  • 3
  • 8
  • 14

4 Answers4

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'
Paul White
  • 94,921
  • 30
  • 437
  • 687
孔夫子
  • 4,330
  • 3
  • 30
  • 50
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
Paul White
  • 94,921
  • 30
  • 437
  • 687
saeed
  • 21
  • 2
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?

mrdenny
  • 27,106
  • 2
  • 44
  • 81
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'
Paul White
  • 94,921
  • 30
  • 437
  • 687
Marcel
  • 11
  • 1