Connection with Azure SQL

459 views
Skip to first unread message

Anil Kumar

unread,
Dec 11, 2014, 9:02:35 AM12/11/14
to pym...@googlegroups.com
Hi,

I am an Test Automation Engineer. We are using Python as Scripting language using pymssql in Windows. Form Python, we need to connect to our Application DB which is Azure SQL. I searched and found that we need to use Free TDS to connect with Azure Database. However, i could not find the steps for installing, configuring Free TDS and how that will be used with pymssql. Please help me considering as a newbie.

What I have done so far:
1. Installed Free TDS for Windows from http://sourceforge.net/projects/freetdswindows/
2.  Below is the settings in Free TDS Config file located at C:\FreeTDS\etc
[global]
    host = localhost
    instance = .
    port = 1433
    client charset = UTF-8
dump file = C:\FreeTDS\etc\freeTDS.log
    tds version = 8.0
    text size = 20971520
3. Now used the below in my Python code
import pymssql
conn = pymssql.connect(
port=1433,
user="username@xxx",
password="password",
database="dbname")
cursor = conn.cursor()
cursor .execute("select * from TableName")

But I am getting error 
  File "pymssql.pyx", line 580, in pymssql.connect (pymssql.c:9055)
InterfaceError: Connection to the database failed for an unknown reason.

Kindly let me know where Im doing wrong

Thanks in advance

Regards,
Anil Kumar

Randy Syring

unread,
Dec 11, 2014, 9:25:51 AM12/11/14
to pym...@googlegroups.com
If you are on Windows, then you can just use the pymssql binary for Windows from pypi, it has FreeTDS bundled with it.

The FreeTDS config file doesn't matter for pymssql.  Only the connection parameters passed to pymssql.connect() matter.

You can use the logging environment variables to get more information about why pymssql/freetds are failing to connect:

http://www.freetds.org/userguide/logging.htm

server="tcp:xxx.database.windows.net",

There shouldn't be a "tcp:" prefix.  Just a DNS host name or IP address.

Randy Syring
Husband | Father | Redeemed Sinner

"For what does it profit a man to gain the whole world
and forfeit his soul?" (Mark 8:36 ESV)


--
You received this message because you are subscribed to the Google Groups "pymssql" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymssql+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anil Kumar

unread,
Dec 12, 2014, 1:10:48 AM12/12/14
to pym...@googlegroups.com
Hi Randy,

Thanks for the info. But still I am getting error in connecting 

  File "pymssql.pyx", line 577, in pymssql.connect (pymssql.c:9000)
OperationalError: (20002, ' DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')


Code Snippet:
connection = pymssql.connect(server='xxxx.database.windows.net',port=1433,user='username', password='passwd', database='dbname')


Regards,
Anil Kumar

Anil Kumar

unread,
Dec 12, 2014, 6:57:54 AM12/12/14
to pym...@googlegroups.com
More info on Version

Python - 2.7
pymssql - 2.0.1 

is there problem with versions, I mean not having the latest?

Ramiro Morales

unread,
Dec 12, 2014, 9:02:31 AM12/12/14
to pym...@googlegroups.com

Yes. Compatibility witj Azure was added in pymssql 2.1.1.

This is described in pymssql documentación.

Anil Kumar

unread,
Dec 12, 2014, 9:12:18 AM12/12/14
to pym...@googlegroups.com
Even not working with pymssql 2.1.1 and Python 3.4

Joseph Idziorek

unread,
Mar 29, 2015, 5:52:22 PM3/29/15
to pym...@googlegroups.com
Any updates?  Has anyone gotten FreeTDS/pymssql to work with Azure SQL Database?

Meet Bhagdev

unread,
Apr 6, 2015, 7:08:41 PM4/6/15
to pym...@googlegroups.com
Interested to know if anyone got this to work in Windows. I can currently get the connection working in Ubuntu but still trying to figure out how to do it in Windows.


On Friday, December 12, 2014 at 6:12:18 AM UTC-8, Anil Kumar wrote:

Uday Guntupalli

unread,
May 25, 2019, 5:32:50 PM5/25/19
to pymssql
Has anyone figured this out ? I have come down this path and I am stuck at the exact same point ? 

Ezequiel Peralta

unread,
Jun 7, 2019, 11:11:02 AM6/7/19
to pymssql
Hello, I am using pymssql with azure sql database. You have to build your username as "xxx@servername" being servername the servername.database.windows.net. and pass the keyword argument tds_version="7.0" for this to work.

Hope it helps
Eze

Akshay L

unread,
Jul 9, 2019, 7:05:13 AM7/9/19
to pymssql
Can not thank you enough. Was searching for this like crazy. It worked like a charm. Thanks a ton.
Reply all
Reply to author
Forward
0 new messages