SQL Server login using different windows credentials

MADHUSUDAN PANWAR 101 Reputation points
2022-11-04T14:04:43.897+00:00

Hi Everyone,

I'm trying to login to SQL Server using Python pyodbc library and I have the different domain windows credentials.
How can I login to SQL server using Python for different domain credentials?

I am able to connect using cmd runas/netonly/user command.

Kind Regards,
Maddy

SQL Server Integration Services
SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. MADHUSUDAN PANWAR 101 Reputation points
    2022-11-10T17:01:06.193+00:00

    Hello everyone,

    I was able to login to sql server using windows credentials with the help of pymssql library and without using runas command. You can go through its official documentation here

    259175-image.png

    Incase it helps someone in the future.

    Kind Regards,
    Madhusudan

    1 person found this answer helpful.

  2. Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator
    2022-11-04T22:29:09.277+00:00

    Your question is a bit unclear. What do you mean with "different domain credentials?"

    If you mean that you are logged on to windows as DOMAIN1\USER1 and you want to connect to SQL Server DOMAIN2\USER2, the best option is probably to start the Python script with RUNAS. There is no way that you can specify through ODBC (or any other client API for that matter) that you want to use a different Windows user. For this to be possible, the other user must be authenticated by Windows. SQL Server cannot do that. It can only accept the token of a user what Windows has already authenticated.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.