platiumky / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Can't upload Images to MS Sql server via pyodbc #373

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by chathura25 on 29 Jun 2014 at 2:03

GoogleCodeExporter commented 8 years ago
try quote field name "image name" into square brackets:
cursor.execute("insert into Database1([image name], image) values (?,?)", 
'new1', bindata)

Original comment by rtu...@itrend.tv on 30 Sep 2014 at 10:45