Python Forum
Connection to MS SQL Database not working - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Connection to MS SQL Database not working (/thread-5259.html)



Connection to MS SQL Database not working - mruprai - Sep-25-2017

I am new to python (ex VBA programmer). I get the error message when trying to connect

[MICROSOFT ODBC DRIVER] Data source name not found and no defualt driver specified.

i am using the following code.

import pyodbc
con = pyodbc.connect("Driver{ODBC Driver 10 for SQL Server};"
"Server=UK171768;"
"Database=PYTHON1;"
"Trusted_Connection=yes;")

cur=con.cursor()
cur.execute('SELECT * FROM dbo.tbl_Customers')
in VBA i can connect using:

sconnect = "Provider=SQLNCLI10; Server=uk171768; Database=PYTHON1; Trusted_Connection=YES;"

any ideaS?


RE: Connection to MS SQL Database not working - buran - Sep-25-2017

It looks like you are missing = after Driver on line#2
https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Windows
by the way, just FYI, I'm using pymssql to work with MSSQL DB