python二进制数据存入数据库_将二进制文件到MSSQL数据库(VARBINARY)与Python pymssql...

I'm trying to insert binary data into an MSSQL database using stored procedures from within an pyramid web application using pymssql.

The MSSQL datatype for the respective column is varbinary(max).

My question is: What does the varbinary datatype of the MSSQL database expect me to do with the binary file before inserting it?

Here's what I've been trying:

with open(tmp_file, 'rb') as content_file:

filecontent = content_file.read()

... and then pass the value of filecontent to the stored procedure.

tmp_file in this case is a valid path to a .png file.

The MSSQL db answers with the following error:

*** DatabaseError: (257, 'Implicit conversion from data type varchar to varbinary(max) is not

allowed. Use the CONVERT function to run this query.DB-Lib error message 257, severity 16:\nGeneral

SQL Server error: Check messages from the SQL Server\n')

I am able to insert the value of the filecontent variable into an SQLite (varbinary column) and a MySQL database (BLOB column) no problem.

Why is it not working with the MSSQL db?

解决方案

Maybe you have to convert the varchar explicitly. That's what your error message implies.

This seems to solve the same problem.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值