Python - Reading FileStream data from SQL Server into memory then output to file -
i trying load in filestream data sql server (via stored proc) , taking byte data , outputting file on disk. need work python 2.7
here have far:
import pymssql def read_blob(filedetailid): conn = pymssql.connect(host="localhost",database="mydb") query = "ops.loadfileblobfromsqlextended '" + filedetailid + "'" cursor = conn.cursor() cursor.execute(query) row = cursor.fetchone() blobfiledata = row[3] filedirectory = 'c:/test/' filename = row[4] + row[5] write_file(blobfiledata, filedirectory + filename) conn.commit() def write_file(data, filename): open(filename, 'wb') f: f.write(data) read_blob("1") i file in directory want , stream of data in row[3] empty shell of file output.
i know missing simple... don't know what.
here equivalent c# code work (i think missing sqlfilestream part in python code)
private static object streamfileobjecttofilefromsqlfilestream(string serverpath, byte[] servertxn, string filedirectory, string filename, string filextension) { using (sqlfilestream sfs = new sqlfilestream(serverpath, servertxn, fileaccess.read)) { using (filestream fs = new filestream(filedirectory + filename + filextension, filemode.create)) { sfs.copyto(fs); } } return null; } any ideas?
thanks,
corey
Comments
Post a Comment