Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map to Network Drive By SQL SP

Is there any way to map to a network drive by using a stored procedure? I have tried:

xp_cmdshell 'net use Q: [shared_network_drive] [pwd] /user:[username]'

but I got an error saying something like

'System error 1312 has occurred.'
'A specified logon session does not exist. It may already have been terminated.'

However, when I run the same command in a cmd console in the same box as the SQL server machine, there is no problem at all. It looks like that SQL process does pass correct logon credential information. Any way to do it by SQL SP?

like image 286
David.Chu.ca Avatar asked Dec 18 '08 18:12

David.Chu.ca


People also ask

Can SQL backup to network drive?

To back up to a network drive when SQL Server is running in a domain user account, the shared drive must be mapped as a network drive in the session where SQL Server is running. If you start Sqlservr.exe from command line, SQL Server sees any network drives you have mapped in your login session.


2 Answers

In an other forum someone posted a tip about how to solve the System error 1312 has occurred. problem by specifying the username including its domain like this:

net use Q: \\[host]\[folder] [pwd] /user:[host]\[username]

I tried it and it worked for me.

like image 191
Martin Avatar answered Sep 23 '22 00:09

Martin


I spent one hour, but the problem solves: You must specify [HOST]\[username] If you write like this: u:/username - it doesn't work

like image 42
KuvaldaMan Avatar answered Sep 21 '22 00:09

KuvaldaMan