Problem with python encoding for mssql

Hi

Using the pymssql library, I want to write data to the MSSQL database, but I am facing encoding problems. Here is my sample code for writing to the database:

# -*- coding: utf-8 -*- import _mssql .... Connection info data here .... def mssql_connect(): return _mssql.connect(server=HOST, user=USERNAME, password=PASS, database=DB, charset="utf-8") con = mssql_connect() INSERT_EX_SQL = "INSERT INTO myDatabsae (Id, ProgramName, ProgramDetail) VALUES (1, 'Test Characters ÜŞiçÇÖö', 'löşüIIğĞü');" con.execute_non_query(INSERT_EX_SQL) con.close() 

Unfortunately, the data recorded in the database is damaged:

enter image description here

The interaction of my mssql db: Turkish_CI_AS How can this be solved?

0
python sql-server character-encoding pymssql
source share
1 answer

Here is a possible solution :

Key INSERT_EX_SQ.encode('your language encoder') . Try instead:

 con.execute_non_query(INSERT_EX_SQ.encode('your language encoder')) 
+1
source share

All Articles