Client-side pyodbc error: “Server does not exist or access denied.”

僤鯓⒐⒋嵵緔 提交于 2020-01-23 12:19:41

问题


I have a python application designed to pull data from a remote database server using pyodbc, then organize and display the data in a spreadsheet. I've had it working fine for several months now, with multiple coworkers in my department using it through a shared network folder.

My connection:

pyodbc.connect('DRIVER={SQL Server};
                SERVER=<myServer_name>;
                DATABASE=<myDB_name>;
                UID=personsUser;
                PWD=personsPassword')

A different employee within our same network recently tried to use the program and got this error:

pyodbc.Error: ('08001','[08001][Microsoft][ODBC SQL Server Driver]
[DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect)')

It looked like a simple permissions issue to me, so to confirm I replaced the userID and password with my own hardcoded in, but it gave the same error. Furthermore the same employee can log in and execute queries through SQL Server Management Studio without issue.

Since everyone else in our department can still use the application fine, I know it must be a client-side issue, but I just can't pinpoint the problem. Any input would be greatly appreciated, Thanks!

Updates:

Per flipperPA's answer below, I updated my connection string to include the port:

con = pyodbc.connect('''DRIVER={SQL Server};
                        SERVER=<myServer_name>;
                        PORT=1433;
                        DATABASE=<myDB_name>;
                        UID=personsUser;
                        PWD=personsPassword;''')

Unfortunately we still got the same error.

He is running 32-bit Windows 7 on an HP machine, the same setup as the rest of the group so it shouldn't to be an os-level issue.

He does operate SSMS on the same machine, but I ran through the telnet check just be sure - no issue there.

I've taught myself the pyodbc API and basic SQL, but I'm still relatively new to the underlying concepts of databases and remote connections. Could you explain the TDS driver a little more?


回答1:


When including SERVER, I've found you often need to include the PORT as well; this is the most likely problem:

pyodbc.connect('DRIVER={SQL Server};
                SERVER=<myServer_name>;
                PORT=1433;
                DATABASE=<myDB_name>;
                UID=personsUser;
                PWD=personsPassword')

I connect mostly from Linux, however. Could it be the other person is connecting from Mac OS/X or Linux? If so, they'll need to use the FreeTDS driver (MS provides one as well, but it is flaky, at best). If you continue to have problems, from the coworkers machine, make sure you can connect from the machine you're having issues with (unless its the same machine they can connect SSMS from):

telnet <myServer_name> 1433

If it connects, you're good, if it hangs on connecting, you're most likely looking at a firewall issue. Good luck!




回答2:


After talking with a knowledgeable friend I was finally able to figure out my issue!

For some reason, the user's system was configured to connect using named pipes, but the server I was connecting to only had TCP/IP protocol enabled. The solution was to force the application to use TCP/IP by adding "tcp:" to the front of the server name.

The fixed connection string:

pyodbc.connect('''DRIVER={SQL Server};
                  SERVER=tcp:<myServer_name>;
                  PORT=1433;
                  DATABASE=<myDB_name>;
                  UID=personsUser;
                  PWD=personsPassword
               ''')


来源:https://stackoverflow.com/questions/31952368/client-side-pyodbc-error-server-does-not-exist-or-access-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!