connection string for a python script to connect sql with a windows account

Hi,

Can someone please advise how a a connection string can be passed to a python script to
connect to sql server with a certain windows service credentials.

I used the below connection string but it takes windows crendentials of the machine
i am connected to not the one i passed in the connection string

'DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName;UID=USERNAME;PWD=PASSWORD;Trusted_Conn¿¿ection=True'


Thanks.
SP_2018 .IT ConsultantAsked:
Who is Participating?
 
Jared_SCommented:
the connection string only specifies information for logging in to the sql server user. The windows user that the script will execute under must be specified in a completely different way.

I've never done that with python, but I pasted a link above to sample code from someone who has accomplished what you are trying to do.
0
 
Manuel Marienne-DuchêneITMCommented:
0
 
Jared_SCommented:
See what happens if you take Trusted_Connection=True out of your connection string
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
SP_2018 .IT ConsultantAuthor Commented:
Hi,

I tried doing that, but it still does not pick up the credentials in the connection string
and executes it with current login credentials.
Is there any way we can force the script to use the credentials given in the connection
 string and not that of the machine login.

Thanks
0
 
Jared_SCommented:
To make sure I understand - this
'DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName;UID=USERNAME;PWD=PASSWORD;

Open in new window

will log into sql server using sql server authentication.

But you're wanting Python to impersonate a Windows user, and connect with Windows Authentication?
0
 
SP_2018 .IT ConsultantAuthor Commented:
Yes you are right, this is exactly my issue.
I have no issues running the script with sql login credentials

I am not able to run scripts with windows credentials passed in the connection string.

When i try doing running it with below connection string

DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DBName;UID=domain\username;PWD=PASSWORD;

the script executes with the windows credentials of the machine i am running this script on
not the windows credentials i pass in the connection string wich is different.

Please advise.

Thanks
0
 
SP_2018 .IT ConsultantAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.