Home > other >  PYTHON access SQL SERVER problems, ace to help solve!
PYTHON access SQL SERVER problems, ace to help solve!

Time:09-20

import pymssql
# open database connection host here='. 'also can use the machine IP or IP + port number (essentially a default port number: 1433)
Conn=pymssql. Connect (host="J freight 330 \ hupeng", user="sa", "=" H * * * * g1980 ", the database="financial bottleneck in the database," charset='utf8')
# use the cursor () method to get your cursor
Cursor=conn. Cursor ()
SQL query statement #
SQL="SELECT * FROM test"
Try:
# executing SQL statements
Cursor. The execute (SQL)
# get all record list
Results=cursor. Fetchall ()
Print (results)
Except:
Print (results)
# close the database connection
Conn. Close ()



in accordance with the above code to run after an error the following problems:

Traceback (the most recent call last) :
The File "C:/Users/198189/PycharmProjects/untitled/learning. Py", line 14, the in & lt; module>
Conn=pymssql. Connect (host="J freight 330 \ hupeng", user="sa", "=" H * * * * g1980 ", the database="financial bottleneck in the database," charset='utf8')
File "SRC \ pymssql pyx", line 636, in pymssql. Connect
File "SRC \ _mssql pyx", line 1957, in _mssql. Connect
File "SRC \ _mssql pyx", line 653, in _mssql. MSSQLConnection. __init__
UnicodeEncodeError: 'ASCII' codec can 't encode characters in the position 0 to 7: ordinal not in range (128)

The Process finished with exit code 1

please everyone a great god help to solve the problem!!!

CodePudding user response:

Excuse me pymssql is this?

CodePudding user response:

Connection is essentially had to use library

CodePudding user response:

The
reference 1 floor kamei is calling, please? Response:
pymssql excuse me what is this?
MSSQL is Microsoft SQL, SQL server is
https://www.cnblogs.com/toheart/p/9802990.html

CodePudding user response:

reference nebuung reply: 3/f
Quote: refer to 1st floor kamei is calling, please? Response:

Excuse me pymssql is this?
MSSQL is Microsoft SQL, SQL server is
https://www.cnblogs.com/toheart/p/9802990.html

Thank you

CodePudding user response:

Try this method, it is very easy to understand, 1, and use. The connect () method to connect to the database, and 2, the use of pandas package read_sql read SQL queries, 3, and writes the result to the DataFrame, can refer to this article, the DataFramehttps://blog.csdn.net/weixin_42261305/article/details/105488253
  • Related