Skip to content

Commit 19f4281

Browse files
authored
Add example: connect using Windows Authentication
I spent a good while figuring out how to specify the database server host+instance, and where to specify the Windows Domain and the user. Solution found here, and confirmed to work with pymssql 2.1.3: https://groups.google.com/d/msg/pymssql/QDMLTGBNeU0/cncYUrkAJD4J
1 parent 5c5737a commit 19f4281

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/pymssql_examples.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ Basic features (strict DB-API compliance)
4444

4545
conn.close()
4646

47+
Connecting using Windows Authentication
48+
=======================================
49+
50+
When connecting using Windows Authentication, this is how to combine the
51+
database's hostname and instance name, and the Active Directory/Windows Domain
52+
name and the username. This example uses
53+
`raw strings <https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals>`_
54+
(``r'...'``) for the strings that contain a backslash.
55+
56+
::
57+
58+
conn = pymssql.connect(
59+
host=r'dbhostname\myinstance',
60+
user=r'companydomain\username',
61+
password=PASSWORD,
62+
database='DatabaseOfInterest'
63+
)
64+
4765
Iterating through results
4866
=========================
4967

0 commit comments

Comments
 (0)