Adaptive Server Connection Failed

916 views
Skip to first unread message

Uday Guntupalli

unread,
May 25, 2019, 5:09:36 PM5/25/19
to pymssql
All, 
     I am trying to connect to an Azure database using pymssql. 

import pymssql  
conn = pymssql.connect(server='xxxxx.database.windows.net', 
                       user='xxxxx@xxxx', 
                       password='xxxx', 
                       database='xxxx'
                      )
     No matter how many different ways i try, I am unable to even connect to the database. I am following the exact example POC shown here: 

     Any help is greatly appreciated. 

Best 
Uday 

Larry Mascarenhas

unread,
May 26, 2019, 11:14:17 AM5/26/19
to pym...@googlegroups.com
Hi Uday... what exception does it indicate during failure? 
Is your database listening on the default port?
Can you specify the port and try?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pymssql/4018ead1-1f39-4f05-a58b-7f5992a3e1e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Uday Guntupalli

unread,
May 26, 2019, 12:16:23 PM5/26/19
to pym...@googlegroups.com
Hello Larry,
       Thank you for responding to my question. I will check with the database admin on the same. When I try on the default port, the error still continues. Do you know if there is a way to check the port for an Azure database using Sql Server ? 

Uday 



For more options, visit https://groups.google.com/d/optout.


--

Best 
Uday 
Active Energy Enthusiast
"Sustainable Energy is the way to go "

Larry Mascarenhas

unread,
May 26, 2019, 12:47:13 PM5/26/19
to pym...@googlegroups.com
Hi Uday..the error message is important to solve the problem. Can you use the try.. except Python methodology to get the error?

Uday Guntupalli

unread,
May 26, 2019, 12:58:56 PM5/26/19
to pym...@googlegroups.com
Larry, 
     I am new to Python, so please be patient with me. I tried the following: 

import pymssql  

def conn_to_dw():
    pymssql.connect(server='xxxxxx.database.windows.net',
                    user='xxx...@firstsolar.com',
                    password='xxxxxxx',
                    database='EDW',
                    port = '1433'
                   )

try:
    conn_to_dw()
except BaseException as e:
    print('Failed in establishing connection: ' + str(e))


This is the error that is captured :
Failed in establishing connection: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (xxxxxx.database.windows.net:1433)\n')


For more options, visit https://groups.google.com/d/optout.

Larry Mascarenhas

unread,
May 26, 2019, 1:17:19 PM5/26/19
to pym...@googlegroups.com
So independent of Python...can you connect to the DB via command line or GUI? Seems to be a transport issue.

Uday Guntupalli

unread,
May 26, 2019, 1:36:51 PM5/26/19
to pym...@googlegroups.com
I am able to connect to the database via Sql Server Management studio without any problem. 


For more options, visit https://groups.google.com/d/optout.

Larry Mascarenhas

unread,
May 26, 2019, 1:41:32 PM5/26/19
to pym...@googlegroups.com
Pymssql uses FREETDS for connectivity. Please review this document regd pymssql and freetds

Gord Thompson

unread,
May 26, 2019, 2:57:41 PM5/26/19
to pymssql
@Uday - Are you working on a Windows machine? Did you install pymssql using ...

pip install pymssql

... ?

Uday Guntupalli

unread,
May 26, 2019, 7:40:33 PM5/26/19
to pym...@googlegroups.com
@ Gord, 
         Yes, I am on a windows machine. I did do a pip install. 

Uday 

--
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.

parachute py

unread,
Jun 5, 2019, 2:25:00 PM6/5/19
to pymssql
1. Try getting the correct port from SQL using 

USE [master]

GO

DECLARE @DynamicportNo NVARCHAR(10);

DECLARE @StaticportNo NVARCHAR(10);

DECLARE @ConnectionportNo INT; -- Look for the port being used in the server's registry

EXEC xp_instance_regread @rootkey = 'HKEY_LOCAL_MACHINE'

,@key ='Software\Microsoft\Microsoft SQL Server\MSSQLServer\SuperSocketNetLib\Tcp\IpAll'

,@value_name = 'TcpPort'

,@value = @StaticportNo OUTPUT

SELECT [PortsUsedByThisConnection] = @ConnectionportNo

,[ServerStaticPortNumber] = @StaticportNo

,[ServerDynamicPortNumber] = @DynamicportNo

GO



2. After providing the port number see what error you get. 


3. If issue still persists, try building pymssql from source. 

pip install --no-binary pymssql pymssql


4. Please publish your findings so that it might help others! 


On Sunday, May 26, 2019 at 7:40:33 PM UTC-4, Uday Guntupalli wrote:
@ Gord, 
         Yes, I am on a windows machine. I did do a pip install. 

Uday 

On Sun, May 26, 2019 at 11:57 AM Gord Thompson <gordon....@gmail.com> wrote:
@Uday - Are you working on a Windows machine? Did you install pymssql using ...

pip install pymssql

... ?


On Saturday, May 25, 2019 at 3:09:36 PM UTC-6, Uday Guntupalli wrote:
All, 
     I am trying to connect to an Azure database using pymssql. 

import pymssql  
conn = pymssql.connect(server='xxxxx.database.windows.net', 
                       user='xxxxx@xxxx', 
                       password='xxxx', 
                       database='xxxx'
                      )
     No matter how many different ways i try, I am unable to even connect to the database. I am following the exact example POC shown here: 

     Any help is greatly appreciated. 

Best 
Uday 

--
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 pym...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages