Reputation: 137
I have freetds.conf
with dbserver connection to database server (which I am routinely using for PHP), the server is on separate server on our own network.
Just to test the connection, I have this small program:
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine(r"mssql+pymssql://{0}:{1}@dbserver/db_database?charset=utf8".format('user','p@ssw0rd'))
def main():
print("In main")
connection=engine.connect()
print("Connected")
if __name__ == "__main__":
main()
The program prints in main, but never gets to connect. How can I debug this kind of problem and what is causing this?
I have no problems connecting with PHP, so there are no network restrictions and I am running this with Python 3.6.
Upvotes: 3
Views: 3558
Reputation: 137
I found the error after all myself. The problem was that there is an instance on SQL server I am using. Though in freetds.conf there is the instance port mentioned, I also had to add it to the create_engine call.
The working version of create_engine is so:
engine = create_engine(r"mssql+pymssql://{0}:{1}@dbserver:12345/db_database?charset=utf8".format('user','p@ssw0rd'))
where 12345 is the port number the instance is listening to.
I am sorry that missed that one crucial information bit, but then again, if I had realized it, I probably wouldn't have even asked - and then somebody else might later fight with the same problem.
hank
Upvotes: 1