I try to figure how connection string, AD & SQL Server works together and I need a little help.
We have a very basic Web app:
- 1 C# app running on .NET 6 (with kestrel)
- 1 SQL Server database
Normally we connect to the database with a connection string like this:
Server=MySQLServer;Initial Catalog=Mybase;User ID=LocalSQLUser1;Password=tutututu;Application Name=MyWebApp;
In this case, my SQL Server's user is a local account on my SQL Server. It work, ok, next.
Another internal team ask us to centralize account in Active Directory. So, I take the MS doc to find how to construct the connection string:
Note
Windows authentication takes precedence over SQL Server logins. If you specify both Integrated Security=true as well as a user name and password, the user name and password will be ignored and Windows authentication will be used.
I construct the new connection string but without login/password :
Server=MySQLServer;Initial Catalog=Mybase;Application Name=MyWebApp;Integrated Security=true;
Questions:
- How can I provide AD Account login & password programmatically with C# if possible?
- If it's possible, is this solution compatible with Linux?