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

11,193

Solution 1

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

Solution 2

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!

Share:
11,193
Alecg_O
Author by

Alecg_O

Actually Batman.

Updated on June 06, 2022

Comments

  • Alecg_O
    Alecg_O almost 2 years

    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?