|
Python Connector for SQL Server Connecting to SQL Server - Python Connector for SQL Server |
|
To establish a connection to a SQL Server database, import the connector and use the connect() method with your connection parameters.
First, import the SQL Server connector module:
import devart.sqlserver
Connect to a database using the connect() module method and obtain a connection object.
You can connect using either mixed mode authentication and Windows authentication.
Mixed mode authentication
For mixed mode authentication, provide your server name, database, user ID, and password:
my_connection = devart.sqlserver.connect("Authentication=Windows;Server=your_server;Database=your_database")
Replace the example values with your actual server name, database, and database credentials.
For more information, see Connection parameters.
Windows authentication
For Windows authentication, provide your server and database names. The connector will use your Windows account credentials:
my_connection = devart.sqlserver.connect("Authentication=Windows;Server=your_server;Database=your_database")
Replace the example values with your actual server and database names.
For more information, see Connection parameters.