将二进制文件到MSSQL数据库(VARBINARY)与Python pymssql [英] Insert binary file into MSSQL db (varbinary) with python pymssql

查看:3047
本文介绍了将二进制文件到MSSQL数据库(VARBINARY)与Python pymssql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想二进制数据插入到使用的存储过程的使用pymssql一个金字塔Web应用程序中的MSSQL数据库。

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

在MSSQL数据类型相应的列是 VARBINARY(最大)

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

我的问题是:什么的MSSQL数据库的varbinary数据类型指望我插入之前与二进制文件做

这就是我一直在努力:

with open(tmp_file, 'rb') as content_file:
    filecontent = content_file.read()

...然后 filecontent 的值传递给存储过程。

tmp_file 在这种情况下是一个巴纽文件的有效路径。

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

在MSSQL数据库的答案,错误如下:

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')

我能够在 filecontent 变量的值插入到一个SQLite( VARBINARY 列)和MySQL数据库( BLOB 列),没有问题。

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

为什么不与MSSQL数据库的工作呢?

Why is it not working with the MSSQL db?

推荐答案

也许你有转换的 VARCHAR 明确。那是你的错误信息意味着什么。

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

请参阅:<一href=\"http://social.msdn.microsoft.com/Forums/sqlserver/en-US/8f9d772a-4fa2-45b4-9fed-f03c73bd757a/implicit-conversion-from-data-type-varchar-to-varbinary-is-not-allowed-use-the-convert-function-to?forum=transactsql\" rel=\"nofollow\">http://social.msdn.microsoft.com/Forums/sqlserver/en-US/8f9d772a-4fa2-45b4-9fed-f03c73bd757a/implicit-conversion-from-data-type-varchar-to-varbinary-is-not-allowed-use-the-convert-function-to?forum=transactsql

这似乎解决了同样的问题。

This seems to solve the same problem.

这篇关于将二进制文件到MSSQL数据库(VARBINARY)与Python pymssql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆