Cannot connect to SQL Server from PowerShell with domain credentials

前端 未结 5 922
旧巷少年郎
旧巷少年郎 2021-01-19 15:20

I have a problem where I cannot connect to a SQL Server using domain credentials. Using the SA credentials it works and the query runs as expected. But when I use domain cre

5条回答
  •  -上瘾入骨i
    2021-01-19 15:45

    If you are not worried about security you can do it like this (not secure, though):

    #Set variables here
    
    $connectionString="server=$s;database=$sqlDbName;user id=$userName;password=$passWord";
    
    $sqlConnection=New-Object System.Data.SqlClient.SqlConnection($connectionString);
    

    It works in SQL Server 2012. But, again, not secure. Hope that helps someone...

提交回复
热议问题