0

i am trying to create an app, which automatically creates and configures merge replication between the 2 PCs in the same local network.

To achieve this, i need to programaticaly create one user on each of the two PCs, this user should have exactly the same user name and passwords as it is required by the replication.

There is no DOMAIN on the network.

I did everything using GUI on both machines and replication works, now i need to do this using a C#. The replication part is done using SQL server 2012 RMO and SMO SDKs.

While googling, i found this (and many many other results which are more or less identical to this). But i believe, that these all examples are meant for local PCs, as it seems people were not getting errors like i do.

My sample code is:

DirectoryEntry directoryEntry = new DirectoryEntry(@"WinNT://WORKGROUP/WIN7-PC,computer", @"admin", "123456");
DirectoryEntry user = directoryEntry.Children.Add("RepTest", "user");
user.Invoke("SetPassword", new object[] { "rep123" });
user.CommitChanges();

I get an error at user.CommitChanges() saying that Access is denied, so i figured i had made a mistake in the authentication details provided to new DirectoryEntry(.... I fixed that and tried again:

DirectoryEntry directoryEntry = new DirectoryEntry(@"WinNT://WORKGROUP/WIN7-PC,computer", @"win7-pc\admin", "123456");
DirectoryEntry user = directoryEntry.Children.Add("RepTest", "user");
user.Invoke("SetPassword", new object[] { "rep123" });
user.CommitChanges();

Now I get the error on the line of .Children.Add(... stating that Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.

When the first time i did it, i checked the Path of user object, which was WinNT://WORKGROUP/WIN7-PC/RepTest, not sure if it has anything to do with anything, but maybe it is trying to use the yet to be created new user folder while being connected as admin user?

Is there a way to get this thing going?

user1651105
  • 1,727
  • 4
  • 25
  • 45
  • Try Using the IP address of the remote server when you try to connect to the network share. – Am_I_Helpful May 04 '16 at 08:28
  • I tried that too. Using the IP behaves the same. I even tried writing random host name or random ip and it did say that network connection could not be established. – user1651105 May 04 '16 at 08:36
  • Obviously, random IP would not work always(you have to use machines within your network)! Did trying IP also resulted in the same error? Check this(don't know if it is helpful) ---> https://support.microsoft.com/en-sg/kb/938120 – Am_I_Helpful May 04 '16 at 08:54
  • What i meant was: i tried the correct IP and got the same error, i then tried the incorrect IP/Hostname to test if it matters and it did as i got that network error. To clarify, my intention is NOT to access a network share, but create a new windows user at the remote host. The connection itself works with and without `,computer` part in the host path, so i am not sure what it is used for. – user1651105 May 04 '16 at 09:06
  • Reading that link you gave just makes me think, that when i connect using admin username, i actually connect to that users folder e.g. C:\Users\admin, when i execute command to create a user "RepTest", it tries to use C:\Users\RepTest, which does not yet exists, but it might be switching the context to `RepTest`, thus the conflict araises as my current context for this connection is `admin`. But thats just my speculations. I hope people who understand this better will come and correct me. – user1651105 May 04 '16 at 09:10

0 Answers0