简体   繁体   中英

pyodbc connection string isn't working - “Data source name not found and no default driver specified”

Recently I'm trying to connect to a SQL Server though pyodbc but I'm having some troubles with the connection string. I already tried as suggested on this previous question: Pyodbc error Data source name not found and no default driver specified paradox , creating a .dsn file and trying to implement the procedure's output on the string, but stil get the same error message: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

This is what I'm doing so far:

conn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};
                      'WSID={BRRIO-xxxx};'
                      'APP={Microsoft® Windows® Operating System};'
                      'Trusted_Connection=Yes;'
                      'SERVER=BRRIO-xxxx\xxx;'
                      'Database=xxx_Data;'
                      'UID="xxxx";'
                      'PWD="xxxx";'
                      )

and this is what my .dsn file looks like:

DRIVER={ODBC Driver 13 for SQL Server};
WSID={BRRIO-xxxx};
APP={Microsoft® Windows® Operating System};
Trusted_Connection=Yes;
SERVER=BRRIO-xxxx\xxx

Any help is really appreciated!

For anyone who's having some troubles with this, I found the solution following the steps here: https://www.sqlserverlogexplorer.com/database-does-not-exist-access-denied/

Basically for me it was a firewall problem, where the port 1433 was blocked. Also, make sure you are using the correct driver for you case ( pyodbc.drivers() , as suggested by @Gord Thompson) and check for remote server connections on yours SQL Server (SQL Server Management Studio > Go to SQL Server instance property > Connections > check Allow remote connection to this server).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM