0
cnxn = pyodbc.connect('DRIVER={ODBC Driver 11 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)

pyodbc.InterfaceError:

('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Talha Israr
  • 654
  • 6
  • 17
gagan
  • 1
  • Probably: https://stackoverflow.com/questions/32662123/pyodbc-error-data-source-name-not-found-and-no-default-driver-specified-paradox – DirtyBit Jan 21 '19 at 14:01
  • 1
    Possible duplicate of [PYODBC--Data source name not found and no default driver specified](https://stackoverflow.com/questions/46045834/pyodbc-data-source-name-not-found-and-no-default-driver-specified) – theduck Jan 21 '19 at 14:26
  • Check the list returned by `pyodbc.drivers()` to see if the driver you're trying to use is visible from your Python app. – Gord Thompson Jan 21 '19 at 14:35
  • @gagan were you able to solve this? – DirtyBit Jan 30 '19 at 08:27
  • Probably this link can solve your issue: https://stackoverflow.com/questions/46045834/pyodbc-data-source-name-not-found-and-no-default-driver-specified/57819021#57819021 – Avnish Tiwary Sep 06 '19 at 09:28

1 Answers1

0

This should work just fine:

import pytds 

SERVER.IP = 'xx.xxx.xxx.xxx'
SERVER.DB_NAME = 'xxxxxx'
SERVER.USERNAME = 'xxxx'
SERVER.PWD = 'xxxxxx'

   with pytds.connect(SERVER.IP, SERVER.DB_NAME, SERVER.USERNAME, SERVER.PWD) as conn:
        cursor = conn.cursor()
        if conn == False:
            print("Error, Could not connect to the database")
        else:
            print("Connected to DB")
DirtyBit
  • 16,613
  • 4
  • 34
  • 55