Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

python - 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-xxxxxxx;'
                      '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-xxxxxxx

Any help is really appreciated!

question from:https://stackoverflow.com/questions/66047455/pyodbc-connection-string-isnt-working-data-source-name-not-found-and-no-defa

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...