We have an application winform C# that connects to sql server 2008 with window authentication impersonation.
We need window authentication because of filestream requirement (we did not find other solution).
The application works fine in domain environnement. Our msi create same user on each computer and we use it to access to remote database.
But a lot of our customer are littre company (1 to 10 employees), they are in workgroup configuration, it is impossible to migrate them on domain environment.
We tried to impersonate but it doesn't works in workgroups :
public void Impersonate(string userName, string domainName, string password, LogonType logonType, LogonProvider logonProvider)
IntPtr logonToken = IntPtr.Zero;
IntPtr logonTokenDuplicate = IntPtr.Zero;
// revert to the application pool identity, saving the identity of the current requestor
_wic = WindowsIdentity.Impersonate(IntPtr.Zero);
// do logon & impersonate
ref logonToken) != 0)
if (Win32NativeMethods.DuplicateToken(logonToken, (int)ImpersonationLevel.SecurityImpersonation, ref logonTokenDuplicate) != 0)
var wi = new WindowsIdentity(logonTokenDuplicate);
View Complete Post