someone on here pushed me in right direction. believe on correct track pull of blobs out of database. thing cannot figure out (i think) set saves to.
here code:
namespace pullblobs { class program { static void main() { string connectionstring = "data source=nyopssql05;initial catalog=opsprod;integrated security=true;user id=username;password=password;"; using (sqlconnection connection = new sqlconnection(connectionstring)) { sqlcommand cmd = new sqlcommand(); cmd.commandtext = "select filename, filedata integrationfile integrationfileid = @request_id"; cmd.connection = connection; cmd.parameters.add("@request_id", sqldbtype.uniqueidentifier).value = new guid("ebff2cea-3ff9-4d22-abef-3240647119cc"); connection.open(); sqldatareader reader = cmd.executereader(commandbehavior.sequentialaccess); while (reader.read()) { // writes blob file (*.bmp). filestream stream; // streams blob filestream object. binarywriter writer; // size of blob buffer. int buffersize = 100; // blob byte[] buffer filled getbytes. byte[] outbyte = new byte[buffersize]; // bytes returned getbytes. long retval; // starting position in blob output. long startindex = 0; // publisher id use in file name. string filename = ""; // publisher id, must occur before getting logo. filename = reader.getstring(0); // create file hold output. stream = new filestream( filename + ".txt", filemode.openorcreate, fileaccess.write); writer = new binarywriter(stream); // reset starting byte new blob. startindex = 0; // read bytes outbyte[] , retain number of bytes returned. retval = reader.getbytes(1, startindex, outbyte, 0, buffersize); // continue while there bytes beyond size of buffer. while (retval == buffersize) { writer.write(outbyte); writer.flush(); // reposition start index end of last buffer , fill buffer. startindex += buffersize; retval = reader.getbytes(1, startindex, outbyte, 0, buffersize); } // write remaining buffer. writer.write(outbyte, 0, (int)retval - 1); writer.flush(); // close output file. writer.close(); stream.close(); } // close reader , connection. reader.close(); connection.close(); } } } } i think have every thing altered way need except set path save files to. here link found on msdn pulled of code (and altered it) from.
https://msdn.microsoft.com/en-us/library/87z0hy49(v=vs.110).aspx
dumb question, there actual blobs in there request id?
furthermore, since reading blobs database , writing them files, why not use bcp?
Comments
Post a Comment