My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 373: Can't upload Images to MS Sql server via pyodbc
1 person starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----


 
Reported by chathura25, Jun 29, 2014
i'm trying to upload an image to MS SQL web-server in Linux(raspbian) environment using python language. so far i had able connect to MS Sql and also i had create a table. And im using pyodbc.

#! /user/bin/env python
import pyodbc 

dsn = 'nicedcn'
user = myid
password = mypass
database = myDB

con_string = 'DSN=%s;UID=%s;PWD=%s;DATABASE=%s;' % (dsn, user, password, database)
cnxn = pyodbc.connect(con_string)
cursor = cnxn.cursor()

string = "CREATE TABLE Database1([image name] varchar(20), [image] varbinary(max))"
cursor.execute(string)
cnxn.commit()
this part complied without any error. that means i have successfully created a table isn't? or is there any issue?

i try to upload image as this way.

with open('new1.jpg','rb') as f:
            bindata = f.read()
cursor.execute("insert into Database1(image name, image) values (?,?)", 'new1', bindata)
cnxn.commit()
i get the error on this part. and it pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS] [SQL Server] Satement(s) could not be prepared. (8180) (SQLParamData)')

can some one help me please. thank you

Sep 30, 2014
#1 rtu...@itrend.tv
try quote field name "image name" into square brackets:
cursor.execute("insert into Database1([image name], image) values (?,?)", 'new1', bindata)


Powered by Google Project Hosting