0

I have a python script running on python 2.7 in CentOS 2.6 that connects to a Sql erver database:

pyodbc.connect("DRIVER=FreeTDS;SERVER=someServer;DATABASE=someDb;UID=myUser;PWD=superSecret;CHARSET=UTF8;TDS_Version=7.2")

That call will fail with the following: pyodbc.Error: ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')

The freetds trace will say login.c:436:invalid port number

Adding PORT=1433; will cause the connection to succeed even though that is the default port number, and I added the following to my freetds.conf:

[global] # TDS protocol version tds version = 7.0 port = 1433

How do I make FreeTDS try port 1433 as the default port so I don't have to set it in the query string?

Justin Dearing
  • 14,270
  • 22
  • 88
  • 161

1 Answers1

0

Instead of this, as you noted:

pyodbc.connect("DRIVER=FreeTDS;SERVER=someServer;DATABASE=someDb;UID=myUser;PWD=superSecret;CHARSET=UTF8;TDS_Version=7.2")

...you could put these values in your connection string, like this:

pyodbc.connect("DRIVER={FreeTDS};SERVER=someServer;PORT=1433;DATABASE=someDb;UID=myUser;PWD=superSecret;TDS_Version=7.2;CHARSET=UTF8")

For your freetds.conf configuration:

[global]
    client charset = UTF-8
    tds version = 7.2

[someServer]
    host = someServer
    port = 1433
    tds version = 7.2

Both ways have always worked for me.

On a side note, I've started using this driver, made by Microsoft specifically for RedHat and CentOS (although I don't know if it will work on a version as old as yours):

https://msdn.microsoft.com/en-us/library/hh568451%28v=sql.110%29.aspx

Best of luck!

FlipperPA
  • 13,607
  • 4
  • 39
  • 71