Blob for binary file, read/write problems

Hi,
I am relatively new to this type of development so apologies if this question is a bit basic.
I am trying to write a binary document (.doc) to a blob and read it back again, constructing the original word file. I have the following code for reading and writing the file:
private void save_addagreement_Click(object sender, EventArgs e)
// Save the agreement to the database
int test_setting = 0;
// create an OracleConnection object to connect to the
// database and open the connection
string constr;
if (test_setting == 0)
constr = "User Id=royalty;Password=royalty;data source=xe";
else
constr = "User ID=lob_user;Password=lob_password;data source=xe";
OracleConnection myOracleConnection = new OracleConnection(constr);
myOracleConnection.Open();
// create an OracleCommand object to hold a SQL statement
OracleCommand myOracleCommand = myOracleConnection.CreateCommand();
myOracleCommand.CommandText = "insert into blob_content(id, blob_column) values 2, empty_blob())";
OracleDataReader myOracleDataReader = myOracleCommand.ExecuteReader();
// step 2: read the row
OracleTransaction myOracleTransaction = myOracleConnection.BeginTransaction();
myOracleCommand.CommandText =
"SELECT id, blob_column FROM blob_content WHERE id = 2";
myOracleDataReader = myOracleCommand.ExecuteReader();
myOracleDataReader.Read();
Console.WriteLine("myOracleDataReadre[\"id\"] = " + myOracleDataReader["id"]);
OracleBlob myOracleBlob = myOracleDataReader.GetOracleBlobForUpdate(1);
Console.WriteLine("OracleBlob = " + myOracleBlob.Length);
myOracleBlob.Erase();
FileStream fs = new FileStream(agreement_filename.Text, FileMode.Open, FileAccess.Read);
Console.WriteLine("Opened " + agreement_filename.Text + " for reading");
int numBytesRead;
byte[] byteArray = new byte[fs.Length];
numBytesRead = fs.Read(byteArray, 0, (Int32)fs.Length);
Console.WriteLine(numBytesRead + " read from file");
myOracleBlob.Write(byteArray, 0, byteArray.Length);
Console.WriteLine(byteArray.Length + " written to blob object");
Console.WriteLine("Blob Length = " + myOracleBlob.Length);
fs.Close();
myOracleDataReader.Close();
myOracleConnection.Close();
This gives the following console output:
myOracleDataReadre["id"] = 2
OracleBlob = 0
Opened D:\sample_files\oly_in.doc for reading
56832 read from file
56832 written to blob object
Blob Length = 56832
My write to file code is:
private void save_agreement_to_disk_Click(object sender, EventArgs e)
string filename;
SaveFileDialog savedoc = new SaveFileDialog();
if (savedoc.ShowDialog() == DialogResult.OK)
filename = savedoc.FileName;
// create an OracleConnection object to connect to the
// database and open the connection
OracleConnection myOracleConnection = new OracleConnection("User ID=royalty;Password=royalty");
myOracleConnection.Open();
// create an OracleCommand object to hold a SQL statement
OracleCommand myOracleCommand = myOracleConnection.CreateCommand();
myOracleCommand.CommandText =
"SELECT id, blob_column " +
"FROM blob_content " +
"WHERE id = 2";
OracleDataReader myOracleDataReader = myOracleCommand.ExecuteReader();
myOracleDataReader.Read();
Console.WriteLine("myOracleDataReader[id] = " + myOracleDataReader["id"]);
//Step 2: Get the LOB locator
OracleBlob myOracleBlob = myOracleDataReader.GetOracleBlobForUpdate(1);
Console.WriteLine("Blob size = " + myOracleBlob.Length);
//Step 3: get the BLOB data using the read() method
byte[] byteArray = new byte[500];
int numBytesRead;
int totalBytes = 0;
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
while ((numBytesRead = myOracleBlob.Read(byteArray, 0, 500)) > 0)
totalBytes += numBytesRead;
fs.Write(byteArray, 0, byteArray.Length);
Console.WriteLine("numBytes = " + numBytesRead + " totalBytes = " + totalBytes);
Console.WriteLine((int)fs.Length + " bytes written to file");
fs.Close();
myOracleDataReader.Close();
myOracleConnection.Close();
This gives the following console output:
myOracleDataReader[id] = 2
Blob size = 0
0 bytes written to file
If I manually add the blob file using the following:
DECLARE
my_blob BLOB;
BEGIN
-- load the BLOB
my_bfile := BFILENAME('SAMPLE_FILES_DIR', 'binaryContent.doc');
SELECT blob_column
INTO my_blob
FROM blob_content
WHERE id = 1 FOR UPDATE;
DBMS_LOB.FILEOPEN(my_bfile, dbms_lob.file_readonly);
DBMS_LOB.LOADFROMFILE(my_blob, my_bfile, DBMS_LOB.GETLENGTH(my_bfile), 1, 1);
DBMS_LOB.FILECLOSEALL();
COMMIT;
END;
COMMIT;
The write to file works perfectly. This tells me that there must be something wrong with my code that is writing the blob to the database. I tried where possible to following the Oracle article using large objects in .NET but that (along with most things on the internet) focus on uploading text files.
Thanks in advance.
Chris.

myOracleCommand.CommandText = "insert into blob_content(id, blob_column) values 2, empty_blob())";
OracleDataReader myOracleDataReader = myOracleCommand.ExecuteReader();
This looks wrong, you shouldn't be using ExecuteReader unless you expect to get a result back. Try using ExecuteNonQuery to do the insert.

Similar Messages

  • Windows 7 applicatio​n file read/write problems

    I'm building a few programs using labview 2009 on an XP machine. I can build these programs and have them work fine with any windows XP machine. Recently I've gotten a Windows 7 machine. I've installed the labview runtime, and daq mx without any problems. The programs seem to run fine.
    However when I have to read or write to files nothing happens. . For instance with one program I log data and output that to a TDM file with the other I read that data and do something. I get the dialog to save the file but after I hit save no file is made. Likewise if I bring a premade TDM file from another machine I get the open dialog box but no data is imported. No Errors are reported.
    Trouble shooting steps taken: I've tried running with administrator rights, with XP compatability mode, in the windows XP virtual machine. Has anyone run into something like this?
    Solved!
    Go to Solution.

    Good Morning. I'm having an identicalissue, but I wanst able to figure out this solution. In simialr fashion (LV 2009 on Win7 machine), I've typically written my executables to write data files to c: so when I deploy the software, I dont have to account for different names. On Win7, this is no longer possible. Can somebody please point me towards a way to define a path constant so I can write and read from a file in a known location without the use having to select a path? Sorry, Ive been looking all night for the solution, just havent been able to get it worked out.  (I did instal the USI files with the Installer) I appreciat the thoughts.

  • Binary File IO DLL Problem

    Hiii
        I have developed one Binary file Read/Write Vi..  and then i have convert that vi in to DLL......
        Now i tested that DLL Vi  it is showing an error No 74. Actually for Binary write i will convert the Input cluster to Flattern to String and for Binary Read i will convert the output to unflattern to string.. I have attached the TEST.vi for reference
    Attachments:
    Binary Read#Write DLL.vi ‏18 KB
    Binary File Read#Write.vi ‏24 KB
    TEST.vi.vi ‏31 KB

    hi there
    if you want to read the size of the string you have to enable the "append array or string size" at the write file function. or you do not append the size and simply read all bytes.
    in any case you should replace existing files to avoid remaining bytes of larger strings written in prior calls.
    See attachment for details.
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"
    Attachments:
    IO.JPG ‏66 KB
    IO_8.5.vi ‏27 KB

  • Binary File Reader to a Chart

    Hello All,
    Newbie having some trouble with reading a chart from a binary file. My problem may be with trying to use a binary file, I am not sure. The x axis time is not the same length as the actual test time. I have acquired a rms voltage from a VCR RF envelope. I'm using a 6009 DAQ with LV 7.1 on Win2K. I have attached the recording vi and the reading vi and a sample file.  I have tried different things including the examples that came with lab view. I need to write a small sized file because this test will last for 4 hours. I have another application that will run for 5 days.  I appreciate any help or ideas.
    Thanks,
    bh3560
    Attachments:
    Chart write_Read.zip ‏140 KB

    Hi,
    The program you have attached acquires, saves and reads data  in ASCII ( floating numbers) and not binary.
    To get an idea on how to write and read data in binary format, look at attached examples( taken from examples shipped with labview)
    Hope this helps
    Regards
    Dev
    Attachments:
    Cont Acq&Graph Voltage-To File(Binary).vi ‏88 KB
    Graph Acquired Binary Data.llb ‏72 KB

  • File read/write in Oracle JVM

    Are there any known issues around file read/write in Oracle JVM. I finally got around the issue of getting the error that says no permission is there by giving <<ALL FILES>> option, but still I don't see a file being created. Any help is appreciated.
    Code:
    try{
    fwriter = new PrintWriter(new FileOutputStream("debugLog.txt",true));
    } catch (IOException ioe) {
    System.err.println("IO Exception for Output File" + ioe.getMessage());
    Thanks.
    -Mujib

    A couple of suggestions:
    1. (Please don't be offended...) I assume you have some stuff like:
    fwriter.println("hello");
    fwriter.flush();
    fwriter.close();
    in your try block?
    2. Try catching FileNotFoundException and SecurityException also.
    3. Try providing a full path on the file just to make sure it's not buried somewhere odd.
    John H.

  • Missing file read/write feature on Mac OS X?

    HI,
    i am missing the file read/write statistics on Mac OS X. First i thought i just need to enable it in the template editor under "Advanced -> Java Application" but the two list items are simple not there. I ve seen a screenshot somewhere from the JMC where the two options are present but not for me. Can anyone tell me if this is a platform issue or how to enable it?
    Thx
    Marc

    You didn't say which version you are using, but I think what you are seeing is that the file and socket events are not available in JDK 8 only in JDK 7. This is a known regression that will be fixed in the next update to JDK 8.

  • [svn] 4069: Fix for - an inherited read-write property is reported as write-only if an overriding setter is present and getter is absent .

    Revision: 4069
    Author: [email protected]
    Date: 2008-11-11 12:24:53 -0800 (Tue, 11 Nov 2008)
    Log Message:
    Fix for - an inherited read-write property is reported as write-only if an overriding setter is present and getter is absent.
    Constructor for mxml files will now have the default comment "Constructor"
    Also fix for asdoc help details doesn;t show description
    QE Notes: Baselines need to be updated.
    Doc Notes: None
    Bugs: SDK-16091, SDK-17863
    tests: checkintests
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-16091
    http://bugs.adobe.com/jira/browse/SDK-17863
    Modified Paths:
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsClass.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsDocUtil.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/TopLevelClassesGenerator.ja va
    flex/sdk/trunk/modules/compiler/src/java/flex2/configuration_en.properties

    Well, running a Windows disk utility on a Mac drive ought to muck things up pretty well. I hope you have backups. If not I suggest you try to backup your files. Then do the following:
    Extended Hard Drive Preparation
    1. Boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger or Leopard.)
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area. If it does not say "Verified" then the drive is failing or has failed and will need replacing. SMART info will not be reported on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Set the number of partitions from the dropdown menu (use 1 partition unless you wish to make more.) Set the format type to Mac OS Extended (Journaled.) Click on the Options button, set the partition scheme to GUID (only required for Intel Macs) then click on the OK button. Click on the Partition button and wait until the volume(s) mount on the Desktop.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.
    Upon formatting completing quit DU to return to the installer. Install OS X. Afterwards you can restore your personal data files and reinstall your third-party software.
    In the future never attempt to use any Windows disk utilities to fix or diagnose a Mac formatted drive.

  • Shortcuts for change in read/write (control/indicator)

    Hello,
    I try to find a shortcut for change to read/write a local variable ?
    Thanks
    Sylvain Jourdan
    (Labview 2012 - English)

    Hi,
    Thanks for you quick answer, I'll suggest this idea in the LabVIEW-IdeaExchange.
    An other idea, do you know if we can add a property to the shorcut menu by modifying a configuration file... ?
    Thanks,
    Sylvain
    Attachments:
    option_menu.png ‏53 KB

  • Binary File Read

    Hello everyone,
    I am not that comfortable with binary file reading. I am trying to learn.
    I have a vi which logs a sine wave in a binary file.
    The Read vi which I have written is not giving the expected data.
    Thanks in advance
    cooldude 
    Attachments:
    Log Data.vi ‏9 KB
    Read Data.vi ‏10 KB

    Attachments:
    Log.JPG ‏20 KB
    Read.JPG ‏13 KB

  • Text_io equivalent for binary files

    Hi!
    I use forms 6:
    Forms [32 Bits] Versão 6.0.8.11.3 (Produção)
    Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
    I believe that what is happening with me its a bug that maybe was fixed in some new patch for forms 6. But I can´t update now.
    I´m trying to load a file (binary) from client (win) to a blob column at server.
    When I use dbms_lob in forms, the form simple crashes. No error, no nothing. It just closes.
    For clob i managed to make a workarround, i create a package at server and i read the text file with text_io at client side and create the clob in the package at server side.
    Now I need to do the same with binary files. There is a way to read and write binary files in forms (client side) without using dbms_lob?
    Thanks.

    You can't use DBMS_LOB on the client-side. DBMS_LOB is a database package and executes always on the database-server. The only chance i see with forms 6i is to somehow transfer te file to to a fileshare on the database-server (maybe ftp) and then use DBMS_LOB on that transferred file.

  • Binary file readed from Labview and Borland C++ v.5

    Hi Everybody!
    My problem is reading binary file from Labview 7.0 and Borland C++ version 5 is not the same.
    Only one difference is "space". Reading from Labview I got "00" (decimal) and reading from Borland C++ I got "32".
    I also try to read this binary file with Matlab 6  and I also got "00" as well as those from Labview.
    I really struck with this problem.. Anybody has an idea about this problem.
    Thanks a lot for anybody help!
    Nok

    Hi,
    These threads regarding reading of binary files was recently discussed in this forum
    You might find some answers for your query
    http://forums.ni.com/ni/board/message?board.id=170&message.id=99016&requireLogin=False
    and
    http://forums.ni.com/ni/board/message?board.id=170&message.id=153565&requireLogin=False
    Regards
    Dev

  • Binary file reading

    Dear All,
    I have Binary file. I want to read Bytes based on Patterns and each channel value (Byte values -- > Float conversion)  and storing it into Index array.
    Please check the attachment for pattren format. 
    Here, the biggest problem is we will get only pattern style, Based on pattern the data is already stored in Binary file just we need to read it means we need to set the Timestamp based on this.
    Please give me some idea to read this kind of pattern files.
    BR,
    Guru
    Munna
    Attachments:
    Data Reading.xlsx ‏15 KB
    Data Reading.xlsx ‏15 KB

    Hi Munna,
    that pattern is quite hard to understand. It seems there is some information missing…
    In your pattern table the data size for e.g. ch1 is given as "1 byte", but in your time schedule you use two bytes for ch1. How are those "ch start position bytes" to be identified?
    Byte values -- > Float conversion
    How do you want to convert those bytes to Float (SGL or DBL)?
    storing it into Index array
    What is an "index array"?
    It seems you have to create a table from your pattern which identifies the bytes in the file. That seems to be the trickiest part as in your pattern#2 example you already have made a mistake (for ch4 there is no marking at timestamp 70ms)…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Binary file reading confusion

    Hi there,
    I'm trying to read a partially binary file with the following structure: The first three lines of the file are regular strings (one can see them correctly when opening the file in a text editor), the rest of the file's contents are integers in their binary form (one cannot see them correctly when opening the file in a text editor).
    How can I read such a file?
    Thanks in advance!
    +P.S.: If you're interested, I'm trying to read a .PPM file (look  here to find out about the format).+

    pfrc wrote:
    Hi there,
    I'm trying to read a partially binary file with the following structure: The first three lines of the file are regular strings (one can see them correctly when opening the file in a text editor), the rest of the file's contents are integers in their binary form (one cannot see them correctly when opening the file in a text editor).
    How can I read such a file?
    Thanks in advance!
    +P.S.: If you're interested, I'm trying to read a .PPM file (look  here to find out about the format).+Use a BufferedInputStream wrapped around a FileInputStream. Read and bytes and until you've hit two end-of-lines, then put those bytes into a String constructor. Note that you'll have to know which line end convention is used, or write your code so as to allow for any of the common ones. After that, continue reading bytes and processing however is appropriate for you.

  • File read write

    Hi guys:
    its an easy question so i will explain as simply and as elborately as possible:
    i am reading from a file
    public void appendFile() {
        try {
          BufferedReader in = new BufferedReader(new FileReader("temp\\text.txt"));
          BufferedWriter out = new BufferedWriter(new FileWriter("temp\\text.txt", true));
          String str;
          String res;
          while ( (str = in.readLine()) != null) {
            res = process(str);
            if (res != null) {
              try {
                out.write(res);
                out.close();
              catch (IOException e) {
                log.info(e.toString());
          in.close();
        catch (IOException e) {
      }what i am trying to do is : read a file read though and where i get a certain string i replace it with another string :
    no looking at this code tell me if i will be writing at the same position or not.. i dont really remember if the cursor for readline and write line is the same :
    forexample : i read through ten lines and find the string i am looking for and i write at that moment witha new strinmg:
    1) will it write on the same line and write over the text that is already written
    OR
    2) will it write on the same line and move the text on that (that i am intending to replace) line to the next..
    OR
    3) will it write in the beginning of the file

    found the error i think : in FileWriter ("",true);
    the true defind that it hould be written in the end of file ... and not the begiining
    now i will see if the flase will write to the beginning or where the readline was done...

  • Can I batch change user access to folders & file read-write permissions?

    I had a corrupted user account on my iMac and after weeks of trying repairs I followed a forum suggestion to delete my account.
    Before doing so I synced all my document folders and files (since 2004) over my LAN to an external hard drive that was attached to my MacMini. I then deleted the iMac account.
    Next I backed up my Mac Mini user account with Time Machine. I then created a new iMac User account on the iMac and let the iMac access Time Machine to bring over all my MacMini preferences, settings, desktop, etc. I now have a fully functioning iMac user account.
    Here is the problem. I attached the USB external drive directly to my iMAC. I can access some of the folders and files on the external hard drive. Most of them refuse to let me acces the folder or open a file. If I use the GET INFO command I see an "_unknown" user with "read and write". I see an "everyone" with "no access". I can individually change each folder and file to allow my user account access and give myself permission to read and write the files. I cannot delete delete the "_unknown" account.
    It will take me days to individually change each folder and file manually like I am now doing.
    Is there a way to use Automator to add my user account to the folder or file and give me read and write folder and file permissions?
    Or is there any other way to do this in a batch change?
    Is there something I need to do to the external files right now that will ensure that I can access them if either computer crashes and I need to replace the MAC? I would hate to have to go through this again. Would having a MAC server instead of an external drive solve this?
    I am using MAC OS 10.6.8 with the most recent updates installed (as of today).
    Thanks,
    Sandi Dickenson

    Select the icon of the external drive in the sidebar of a Finder window, and open the Info window. In the "Sharing & Permissions" section of the window, click the lock icon and authenticate. Make sure you have read & write access to the volume by changing the settings if necessary. Then, from the action menu (gear icon), select "Apply to enclosed items."
    The "_unknown" user and group are assigned automatically to files on a volume with the "Ignore permissions" option set.

Maybe you are looking for

  • Difference b/n null and ""

    hi all can any one tell me the difference between, String a = ""; String a = null; Which one is better to use ???

  • How to create search/Entry screen in Oracle apps forms.

    HI All, I want to develop a form in such a way that if user enter the values in the master block and Tab out or if i use a button GO then all the detailed records need to be display in the detailed block field, if thers no matching data in the detail

  • Best way to build a website with hundreds of pages

    What is the best way to build a website with hundreds of pages that include businesses in every city of the U.S. I will be building it in Dreamweaver CS4 and pulling the data from an MS Excel spreadsheet. I started building it by building the first p

  • Issue Tracking Application

    Can someone please help. I have been through Chapter 10 of the 2 Day Play Application Express Developer Guide 2.1, "How to Build and Deploy an Issue Tracking Application". At run time when I select the Delete button, the confirmation box appears. Sel

  • WAS 6.4 Download

    Hello. Does anyone know where to find the download of webas 6.4? It says it is in general release but I cannot find it anywhere. This link points to an internal intranet at SAP. https://websmp106.sap-ag.de/~sapidb/011000358700002886122003E/ReleaseInf