Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 876
  • Last Modified:

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.
0
Sonali P
Asked:
Sonali P
  • 4
  • 3
1 Solution
 
Manuel Marienne-DuchêneITMCommented:
0
 
Jared_SCommented:
See what happens if you take Trusted_Connection=True out of your connection string
0
 
Sonali PDatabase AdministratorAuthor 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
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
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
 
Sonali PDatabase AdministratorAuthor 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
 
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
 
Sonali PDatabase AdministratorAuthor Commented:
Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now