How to allow sql server 2019 to access maped network drive ?

ahmed salah 3,216 Reputation points
2022-08-10T22:37:19.61+00:00

I work on sql server 2019 i create maped drive with letter S and on same server 7.7 i make mapped network drive S
but can't access to this drive
so how to access it please

i try as following
EXEC xp_cmdshell
'S: \\192.168.7.7\ExportExcel SM@trkrish /USER:******@z2data.com /PERSISTENT:yes'

and give me result

output  
The system cannot find the drive specified.  
NULL  

why it show drive not found The system cannot find the drive specified

i can open maped network drive and write to it and read it manually
but from sql server it not working
so what i do please to solve issue

Developer technologies Transact-SQL
SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2022-08-11T02:14:16.073+00:00

    Hi @ahmed salah ,

    There is some mistakes in your command, please refer to below command to adjust your command.

    EXEC xp_cmdshell ‘net use <driver letter> \\<servername>\<sharename> /user:<username> <password>’  
    

    For example:

    You can write the above statement as follows:

    EXEC xp_cmdshell 'net use z: \192.168.1.1\shareddrive /user:YOURUSERNAME PASSWORD'

    Once you run the above code it will map your shared folder share drive from the server 192.168.1.1 to the local system as a Z: drive.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.
    0 comments No comments

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-08-11T21:53:46.307+00:00

    Disk mappings are per login session. So your personal mappings are unknown to SQL Server.

    Thus, if you want to use the mapped drive, you need to map it from inside SQL Server:

       EXEC xp_cmdshell 'NET USE P: \\SUVEMETS\C /USER:user YourPassword'  
    

    But beware that this permits all users on the server to access the share with your credentials.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.