Connecting to DB with Server Group instead of username and password with pyodbc

I am trying to connect to a database from python using pyodbc that I currently have set up on Azure Data Studio. When setting up on Azure Data Studio, I don't supply a username/password but rather a server name and a server group (a global group that gives access to the db). How can I achieve something like this with pyodbc?

I attempted just using my username and password but it gives me a Login Failed for user error. I also attempted logging in by specifying the domain i.e MS\username. I checked the pyodbc docs and don't see any parameters for a server group and checked the docs from Microsoft for connecting using pyodbc and didn't see anything about connecting with a Server group

import pyodbc
server = ''
database = 'dbname'
username = 'MS\uname'
password = ''
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)

1 Answer

  1. Lee- Reply


    I just needed to add the Trusted_Connection parameter to the connection string.

    cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD=' + password+';Trusted_Connection='+TC)

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>