(known) Issue:
I have a specific application part in order to create a user home drive on a network location:
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(myadmin,pwd);
using (new NetworkConnection(@"\\server\Data\Home", cred))
{
string path = $@"\\server\Data\Home\{userName}";
Directory.CreateDirectory(path);
SetFullPermission(path, userName);
}
In some occurrences, the code above might fail with the following error message:
Multiple connections to a server or shared resource from the same user using multiple usernames are not allowed. Disconnect all previous connections to the server or shared resource, and try...
Cause:
The error is caused if my local user on the machine had the network drive open at any given time (also if the folder is closed again) or if the home drive was mapped at any given time (until computer is rebooted)
Workaround:
- Remove home drive from user and remove logon script (so that no drives to the server are automapped)
- Reboot the computer and log on
- Execute the software
- When task is finished, add logon script and home drive to own user again and relogon, in order to have access to network drives
Question:
Is there a way to cancle any given relevant network connection prior to using (new NetworkConnection(@"\\server\Data\Home", cred)) in my c# application?