I have a local DB on my machine called 'Test' which contains a table called 'Tags'. I am able to access this DB and query from this table through SQL Server management studio 2008.
However, when using pyodbc I keep running into problems.
Using this:
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost:1433;DATABASE=Test')
yields the error:
pyodbc.Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]Invalid connection. (14) (SQLDriverConnectW); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Invalid Instance()). (14)')
(with or without specifying the port)
Trying an alternative connection string:
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost\Test,1433')
yields no error, but then:
cur = conn.cursor()
cur.execute("SELECT * FROM Tags")
yields the error:
pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Tags'. (208) (SQLExecDirectW)")
Why could this be?
Connecting to MySQL from Python using ODBC Driver for MySQLFirst we import the pyodbc module, then create a connection to the database, insert a new row and read the contents of the EMP table while printing each row to the Python interactive console.
Top Alternatives to pyodbcThe AWS SDK for Python. Pytest: simple powerful testing with Python. Python wrapper for the Cloudflare v4 API. Powerful data structures for data analysis, time series, and statistics.
Oracle database storage comes with ODBC support, but in order to connect to Oracle from Windows, macOS, or Linux, you must install ODBC driver for Oracle, otherwise the pyodbc module will not be able to establish a connection to the database.
I tried changing your query to
SELECT * FROM Test.dbo.Tags
and it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With