I have built a Windows Forms GUI to connect to a SQL Server using Windows Authentication. Authentication works on our old machines with the old Windows accounts “a.com/username”. We have received new machines and with Windows accounts on a new domain “b.com/username”.
I can connect to the server using SQL Server Management Studio using the runas command.
runas /netonly /user:a.comusername "<path>ssms.exe"
However, when I try to the same using my custom built application the handshake fails when trying to authenticate while running a SQL query.
I build my connectionString as follows:
string ConnectionString;
System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
builder["Data Source"] = "server-adress";
builder["Initial Catalog"] = "db-name";
builder["Integrated Security"] = "SSPI";
connectionString = builder.ConnectionString;
I would have assumed that using Integrated Security = SSPI
would use the Windows Authentication that I pass from the runas command like it does with ssms, but this does not seem the case. Do I need to implement some feature in my application to be able to use the runas command with it?
Weber is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.