Tuesday, February 12, 2019

py0008 : connection with sqlserver database

First of all you need to install pyodbc package if not you might face this error "unknown command pyodbc"

Open cmd and use below command to install :
pip install pyodbc

Helpfull Link :

py0003 : pip install selenium SyntaxError: invalid syntax, while install selenium


install above package. for me it is very easy step, to install this package connect with database without any error in single shot.

I used below code to connect with database.

import pyodbc
crsrconnection = pyodbc .connect("Driver={SQL Server Native Client 11.0};"
                      "Server=IPAddress Or Server Name\Instance;"
                      "Database=****;"
                      "Trusted_Connection=yes;pwd=****")


cursor = crsrconnection.cursor()
cursor.execute('SELECT count(*) rn FROM sametable')

for row in cursor:
    print(row)

No comments:

Post a Comment

web stats