Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i am updating an exe file to blobfield database. Code is as below

FileStream fls = new FileStream(@filepath, FileMode.OpenOrCreate, FileAccess.Read);
                    byte[] blob = new byte[fls.Length];
                    fls.Read(blob, 0, System.Convert.ToInt32(fls.Length));
                    fls.Close();
                   string query = "update employee set doc = :BlobParameter ";
                        OracleParameter blobParameter = new OracleParameter();
                        blobParameter.OracleType = OracleType.Blob;
                        blobParameter.ParameterName = "BlobParameter";
                        blobParameter.Value = blob;
                        OracleCommand cmd = new OracleCommand(query,conn);
                        cmd.Parameters.Add(blobParameter);
                        cmd.ExecuteNonQuery();
                        conn.Close();
                        conn.Dispose();
                    }


But when retreive with the code as below, it does not work properly

string sql = "Select doc from employee where docId = '121'";
OracleCommand cmd = new OracleCommand(sql, conn);
OracleDataReader dataReader = cmd.ExecuteReader();
dataReader.Read();
OracleLob blob = dataReader.GetOracleLob(0);
dataReader.Close();
// Create a byte array
byte[] byteData = new byte[0];
// fetch the value of Oracle parameter into the byte array
byteData = (byte[])blob.Value;
// get the length of the byte array
int ArraySize = byteData.GetUpperBound(0);

// Write the Blob data fetched from database to the filesystem at the destination 
FileStream fs1 = new FileStream(FilePath, FileMode.OpenOrCreate , FileAccess.Write);
fs1.Write(byteData, 0, ArraySize);
fs1.Close();



Please suggess that is there any other unicode concept.
Thanks in advance
Posted
Updated 19-Jan-12 4:48am
v2
Comments
Reiss 19-Jan-12 11:30am    
Why not store the exe on file system and hold a reference to its location in the database?
[no name] 19-Jan-12 11:43am    
IMO it is not practical to store exe in database. Many applications come with multiple files and config settings. It would need saved to the file system run anyway.
Sergey Alexandrovich Kryukov 19-Jan-12 12:08pm    
If you had this crazy idea of storing and perhaps executing executable files in database and implemented it, I would perhaps understand.

If you had a problem implementing some good idea, it would worth helping.

Combination of the two does not deserve any help. Why wasting time on it? You got my vote of 1, sorry.
--SA

1 solution

Why play with filestreams?
C#
byte[] data = File.ReadAllBytes(path);
...
File.WriteAllBytes(path, data);
That way, you aren't doing or implying any Unicode, or other conversions. The bytes are then just stored and retrieved as binary byte data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900