PYMSSQL - error

Asked

Viewed 419 times

0

People I am facing a problem with pymssql library, whenever I try to make a connection it presents the error below:

inserir a descrição da imagem aqui

This is the connection str:

import pyodbc

con = pyodbc.connect("DRIVER={SQL Server};server=localhost;database=teste;uid=sa;pwd=TesteCon@123")

cur = con.cursor()
cur.execute("Select * from test")
for row in cur:
    print row.nome + ',' + row.email + ',' + row.id
cur.close()
con.close()

1 answer

0


It is a disuse warning (Deprecationwarning) of the collections, this alert has now started in version 3.7 of Python.

https://docs.python.org/3.7/whatsnew/3.7.html#id3


Collections

In Python 3.8, the Abstract base classes in collections.abc will no longer be Exposed in the regular Collections module. This will help create a clearer Distinction between the Concrete classes and the Abstract base classes. (Contributed by Serhiy Storchaka in bpo-25988.)


From version 3.8 the old way of importing the module will no longer be supported.

If you’re not doing this import the connector maintainer should update it at some point.

Regarding the pymssql it is listed as a connector option, however the official SQL server site says:


There are several Python SQL drivers available. However, Microsoft puts its testing efforts and its trust in pyodbc driver.


How Microsoft tests and helps in the development of pyodbc I believe he’s a more interesting option than the pymssql.

Your connection string is different in the driver also:

pyodbc

https://docs.microsoft.com/pt-br/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-2017

import pyodbc 
# Some other example server values are
# server = 'localhost\sqlexpress' # for a named instance
# server = 'myserver,port' # to specify an alternate port
server = 'tcp:myserver.database.windows.net' 
database = 'mydb' 
username = 'myusername' 
password = 'mypassword' 
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()

pymssql

https://docs.microsoft.com/pt-br/sql/connect/python/pymssql/step-3-proof-of-concept-connecting-to-sql-using-pymssql?view=sql-server-2017

import pymssql
conn = pymssql.connect(server='yourserver.database.windows.net', user='yourusername@yourserver', password='yourpassword', database='AdventureWorks')
  • I resorted to the pyodbc self and was successfully obliged!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.