Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I need to store my database on a NAS drive and the shared volume requires a username and password. I am not in charge of the storage drive so I cannot change it. Is there a way to add the username and password in the connection string in c#. thanks

What I have tried:

I tried placing the credentials in front of the path like what you would do for FTP.
Posted
Updated 5-Jan-20 21:03pm

1 solution

No, you can't add a set of credentials to a file path - which is what you'd need to connect to the share and specify the path in an DB connection string.

You can do this: Connect to a UNC Path with Credentials[^] - but I'd go with establishing a mapped drive letter to the share in Windows, and just use that directly as part of the file path.

You can establish the map directly in software: Mapping a Drive Letter Programmatically[^] if you need to perhaps as a "one off" at the app start, if the map is not already connected.
 
Share this answer
 
Comments
Maciej Los 6-Jan-20 10:26am    
Agree!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900