I am trying to connect to SQL Server using pyodbc to query some tables for work. I am able to connect to one of our servers and run a SQL query, but the same code does not work for a different server. The error message I get is this:
Error: ('008001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]
SQL Server does not exist or access denied. (17) (SQLDriverConnect)')
This is the code that I'm using:
import pyodbc
import pandas as pd
conn = pyodbc.connect('Driver={SQL Server};'
'Server=servername;'
'Database=databasename;'
'Trusted_Connection=yes;')
[rest of code]
The code works for one server, but when I change the server & database names to the other, I get the error message (there are no spelling errors in the server/database names). I am able to access this server through SQL. Additionally, I am able to access this server and to query/update its tables using Excel VBA (even though it will not connect in Python).
Based on my research, there are many possible issues that I do not fully understand. I have tried changing the driver name in the code, and that failed. Since this code is for work, there are security permissions that prevent me from trying out certain solutions.
What could be causing this issue? If somebody could point me in the right direction, that would help me ask better questions of our IT team, if I'm not able to solve it myself.
(I'm using Microsoft SQL Server Management Studio 17 and Python 3.6 with Spyder.)