10

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.

  • Hello, to avoid being flagged down or having your question deleted by the mods, please provide more information. How are you trying to connect to another server by using SQL Server Management Studio exactly? Are you using powershell? XP_CMDSHELL? Your NET USE command is totally wrong as well. I don't see how that would work anywhere, inside or outside of SQL Server. You need 2 backslashes (\) and a folder for it to work. – Ali Razeghi Oct 25 '12 at 5:30
  • Is there a typo in the net use statement? I'd expect something like: NET USE H:\ \\server\share 1234abc /USER:cranew /PERSISTENT:yes – Stuart Moore Oct 25 '12 at 6:53
  • Mapping a network drive like this is really not a good idea, for reasons mentioned in the answers below. Why would you not just use a UNC path instead? – Daniel Hutmacher Mar 23 '16 at 7:42
  • @DanielHutmacher, and how would that look like, please!? – Paul-Sebastian Manole Apr 27 '17 at 13:31
  • @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. – Daniel Hutmacher Apr 27 '17 at 13:35
6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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