Hi forum,
I'm trying to connect from a powershell script to a mssql database. Everything works fine when using SQL User accounts. When using NT-User accounts the authentication fails. For NT-User I'm setting "Integrated Security=true" in the connection string. This seems to ignore the userid and pwd and use the local user account (system-user in my case) and is not correct. When setting "Integrated Security=false" the authentication fails because is seems that the script is assuming a SQL User account.
so how the would it be possible to connect to the database using an NT User account? Thanks for your help in advance!
here is a example function:
function test_ima_db {
$SQLCommand="SELECT * FROM INFORMATION_SCHEMA.TABLES"
$connectionstring = "Server = 192.168.0.1; Database =xenapp6-datastore1; UID=testdomain\testuser; Password=testpassword; ;Integrated Security=true"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = $connectionstring
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SQLCommand
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$dsdatabasefound = $DataSet.Tables[0].Rows.Count
$SqlConnection.Close()
}
test_ima_db