I have written a Windows service which connects to a SQL Server (2014 in this case) using Windows authentication with credentials received from the user. In order to do so I use impersonation, specifically the Simple Impersonation nuget.
On my local environment (Windows 10) and on other local environments it seem to work fine, but once I try to test it in Google cloud (Windows Server 2012 R2), I get a login failed exception for the user I was trying to impersonate to, which might suggest there is an issue that I can't find with the password.
I use the same user and password I'm using to connect via RDP to the server. When using SSMS to connect to the same database with that user windows authentication works.
Does anyone has any idea what's wrong? Is Windows authentication in anyway different on cloud or on windows server?
var sql = "select 1";
using (Impersonation.LogonUser(domain, userName, password, LogonType.Interactive))
using(var con = new SqlConnection(connectionString))
{
con.Open();
var cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
Thanks
It was all a security issue. Since a different user installed the DB a login wasn't created to my user, and since it's on cloud and not our domain I'm also not one of the builtin users. Creating a login fixed it, obviously. I feel stupid