1

I am using following code to connect with SQL 2008 R2:

cnxnStoneedge = pyodbc.connect("DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=myDB;UID=admin;PWD=admin")

Which gives error:

Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect)')
      args = ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNE...t exist or access denied. (17) (SQLDriverConnect)')
      with_traceback = <built-in method with_traceback of Error object>

I am not sure whether SQL connecting via named Pipes or TCP, I did enable IP Address. Attaching Screen Shot enter image description here

Volatil3
  • 14,253
  • 38
  • 134
  • 263
  • Does this help: http://stackoverflow.com/questions/7753830/mssql2008-pyodbc-previous-sql-was-not-a-query – Torxed Jan 19 '14 at 09:38
  • No it does not. I am just making connection, rather than executing an SP – Volatil3 Jan 19 '14 at 09:43
  • Yes but my initial problem was actually the connection, despite my error message. More often than not, it's the driver that's the root cause not the programming. – Torxed Jan 19 '14 at 09:49
  • I am getting error on the line I put above. Yes I know it's about driver but I am not being able to figure out how SQL Server is trying to connect – Volatil3 Jan 19 '14 at 09:58
  • have you installed the "Microsoft SQL Server 2012 Tool-kit" portfolio? The ENTIRE thing (including MSSQL Administrator)? because it looks to me like you're using the native windows SQL Driver which won't work. You need to connect (name) to it via `DRIVER={SQL Server Native Client 10.0}` – Torxed Jan 19 '14 at 10:51
  • 1
    Your screenshot shows that you are running SQL Server Express Edition, so try using this clause in your connection string: `Server=(local)\SQLEXPRESS;` (instead of `SERVER=127.0.0.1;`) – Gord Thompson Jan 19 '14 at 12:29

1 Answers1

4

The following test code works for me to connect Python 2.7.5 with SQL Server 2008 R2 Express Edition:

# -*- coding: utf-8 -*-
import pyodbc

connStr = (
    r'Driver={SQL Server};' +
    r'Server=(local)\SQLEXPRESS;' +
    r'Database=myDb;' +
    r'Trusted_Connection=Yes;'
    )

db = pyodbc.connect(connStr)

cursor1 = db.execute('SELECT [word] FROM [vocabulary] WHERE [ID]=5')

while 1:
    row = cursor1.fetchone()
    if not row:
        break
    print row.word
cursor1.close()
db.close()

and the following connection string also works for me because my \SQLEXPRESS instance is listening on port 52865:

connStr = (
    r'Driver={SQL Server};' +
    r'Server=127.0.0.1,52865;' +
    r'Database=myDb;' +
    r'Trusted_Connection=Yes;'
    )
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418