Cannot connect to SQL Server from PowerShell with domain credentials

前端 未结 5 976
旧巷少年郎
旧巷少年郎 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条回答
  •  野性不改
    2021-01-19 15:30

    You cannot connect with domain credentials THAT WAY.

    Domain credentials are present in the process making the connection. The account using in the process (or if using the NETWORK ONLY option in RUNAS) will be used to make the connection to SQL Server using integrated security.

    Of course, because your process CANNOT actually run as a user on that domain because your computer is not in a trust relationship with that domain, I recommend you look at using RUNAS /NETONLY.

    This will prompt for a password, and so you may have to write your own replacement for it which uses the CreateProcessWithLogonW API instead.

    https://stackoverflow.com/a/758805/18255

    This will allow your process to use domain credentials from the other domain which are only used on network connections and verified at that time, while still using the local account for other things. This MAY cause problems getting to other network resources which might rely on your local (or other domain?) account, I haven't fully tested how RUNAS /NETONLY works if you make DIFFERENT network connections from the same process.

提交回复
热议问题