I have a C# windows application from which I need to connect to a SQL Server database and access the tables, with a different windows account.(Other than the logged in account)
What is the best approach for this.
I have a C# windows application from which I need to connect to a SQL Server database and access the tables, with a different windows account.(Other than the logged in account)
What is the best approach for this.
Most commonly for SQL Server, I would use integrated security, so a connection string like this:
var connectionString = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;", hostName, databaseName);
If you need to connect as a different user, which you're not logged in as, then you need to specify the username / password combination in the connection string, like this:
var connectionString = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3};", hostName, databaseName, anotherUsername, anotherPassword);