gordthompson / sqlserverport

lookup SQL Server instance port from Linux client
Apache License 2.0
19 stars 5 forks source link

socket.gaierror: [Errno -2] Name or service not known #1

Closed omaralt closed 4 years ago

omaralt commented 4 years ago

Hi I'm developing in Linux for work for the first time and have been struggling to connect to SQL Server on an AWS instance via pyodbc. I have installed the Drivers via the MS webpage and have moved sqlserverport.py to my packages dir but am getting a socket error. Mine is on 1433 though slightly different to 1433. I am also not sure if the connect string is properly formatted either.

Any feedback would be appreciated, thanks :)

Ubuntu in AWS Cloud9 env running Python3.6

Code:

servername = 'salesdatinst.beer7n7la6f.us-north-1.rds.amazonaws.com,1433'
serverspec = '{0},{1}'.format(
    servername,
    sqlserverport.lookup(servername, 'SQLEXPRESS'))

cnxn = pyodbc.connect('DRIVER=ODBC Driver 17 for SQL Server;SERVER{};....format(serverspec);DATABASE=sales;UID=diego1986;PWD=notapw')

Below is the error message

Traceback (most recent call last):
  File "/home/ubuntu/environment/pyspark-etl/conn-pandas.py", line 8, in <module>
    sqlserverport.lookup(servername, 'SQLEXPRESS'))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/sqlserverport.py", line 35, in lookup
    sock.sendto(udp_message, (server, udp_port))
socket.gaierror: [Errno -2] Name or service not known
gordthompson commented 4 years ago

Your servername string already specifies port 1433. If that is correct then you don't need to use sqlserverport because you already know the port number.

If you really do need to look up the port number by instance name (which I sort of doubt, for amazonaws) then remove the port number from the servername string.

omaralt commented 4 years ago

Ok thanks, are there any troubleshooting guides for pyodbc and linux? :)

gordthompson commented 4 years ago

There's this ...

https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Linux

... but I suspect that you may have seen it already.