Reputation: 1781
How can I connect to MS SQL Server database remotely by IP in Python using mssql and pymssql modules. To connect locally I use link = mssql+pymssql://InstanceName/DataBaseName
I enabled TCP/IP Network Configurations. But How can I get the connection link?
Thank you.
Upvotes: 1
Views: 3255
Reputation: 9986
You need to create a Connection
object
import pymssql
ip = '127.0.0.1'
database_connection = pymssql.connect(host=ip, port=1433, username='foo', password='bar')
If you're using SQLAlchemy, or another ORM that supports connection strings, you can also use the following format for the connection string.
'mssql+pymssql://{user}:{password}@{host}:{port}'
Upvotes: 5