连接字符串: conn = pyodbc.connect(Driver={SQL Server};Server=127.0.0.1;Database=dbname;Uid=sa;pwd=sa;autocommit=true)
download:pymssql,文档:http://pymssql.sourceforge.net/documentation.php
连接字符串:conn = pymssql.connect(host='192.168.31.99', database='gvss_sale', user='gvss', password='gvss')
pymssql的限制:
image
data is truncated to 4000 characters.
This is known limitation of DB-Library for C. I know of no workaround. This issue is also present in PHP, the solution suggested was to use ODBC protocol.
varchar
andnvarchar
data is limited to 255 characters, and longer strings are silently trimmed.
This is known limitation of TDS protocol. A workaround is toCAST
orCONVERT
that row or expression totext
data type, which is capable of returning4000 characters.
- column names are limited to 30 characters and longer names are silently truncated.
There's no workaround for this. You have to use names (or aliases as inSELECT columnAS alias
) that are not longer than 30 characters.
- "
SELECT ''
" statement returns a string containing one space instead of an empty string.
There's no workaround for this. You cannot distinguish between
SELECT '' -- empty string
and
SELECT ' ' -- one space
- "
SELECT CAST(NULL AS BIT)
" returns False instead of None.
There's no workaround for this. You cannot distinguish between
SELECT CAST(NULLAS BIT)
and
SELECT CAST(0AS BIT)
You should avoidNULL
bit fields.Just assign a default value to them and update all records to the default value.I would recommend not usingBIT
datatype at all, if possible change it toTINYINT
for example.The problem will disappear, and storage overhead is unnoticeable.This issue is also known for example in Microsoft's own product, Access, seeKB278696 article.
- New features of SQL Server 2005 and SQL Server 2008 are not supported.
Some of the features of SQL Server versions newer than 2000 just don't work.For example you can't use MARS feature (Multiple Active Result Sets). You haveto arrange your queries so that result sets are fetched one after another.
- The newest version of
ntwdblib.dll
library v. 2000.80.2273.0 is unusable.
If on Windows, please use the library bundled with pymssql package. Older or newer versionsmay introduce unexpected problems, the version mentioned above causes memory violation errors,but only in certain scenarios, making tracing the cause very difficult. More information is also available on FAQ page.