.Net SqlConnection class with Windows authentication

32 views Asked by At

I'm using PowerShell System.Data.SqlClient.SqlConnection class to create connection to my remote MsSQL server. Connection string looks like these:

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$Server,$port; Database=$database; User ID=$software_user; Password=$software_password;"

That thing works fine, but I have to use Windows authentication to connect, not MsSQL internal account. The problem is, that Windows authentication don't have an option to specify which account will be used and it using same account as powershell.exe process. Example: I have an account with name MyOrg\Someuser. I'm "Run as" Powershell exe as these user and now Windows authentication will try to use MyOrg\Someuser account to connect to MsSQL server

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$Server,$port; Database=$database; Integrated Security=True"

How can I specify a different account with Windows authentication without changing "Run As" user for Powershell.exe process? Specifying credentials with Integrated Security=True option doesn't work

0

There are 0 answers