|
Am I extracting the blob file correctly?
Private Function decryption()
'This is function is the same as encryption with just a few changes'
'loading the xml document'
Dim key As Byte()
Dim IV As Byte()
'The hardcoded password goes here'
'This is a section just in case you want to a password to your encrypted files'
key = keyencryption(LoginForm.Password_TextBox.Text)
IV = IVCreation(LoginForm.Password_TextBox.Text)
'if there is an error in the application. A error message will be displayed'
Try
'checking to make sure the text box isn't null'
If (Decrypt_TextBox.Text = "") Then
MessageBox.Show("Need to put in the file location or select file in grid for decryption")
Else
'declaring string for file'
Dim filename As String
'Getting the file name that is selected'
filename = getFilename()
'Starting to abstract the data from the database'
database.ConnectionString = "Data Source = FileVault.db3;"
database.Open()
Dim command As SQLite.SQLiteCommand
Dim sqlstatement As String
command = database.CreateCommand
'The following will get the bytes of the file'
Dim filesize As Integer
sqlstatement = "SELECT FileSize From Vault WHERE FileName=@file;"
command.CommandText = sqlstatement
command.Parameters.AddWithValue("@file", filename)
Dim reader As SQLite.SQLiteDataReader
reader = command.ExecuteReader
filesize = reader.GetValue(0)
reader.Close()
MessageBox.Show(filesize)
Dim data(filesize) As Byte
'The following should get the data'
sqlstatement = "SELECT FileData FROM Vault WHERE FileName=@file;"
command.CommandText = sqlstatement
command.Parameters.AddWithValue("@file", filename)
Dim buf() As Byte
'This gets the file from the database'
reader = command.ExecuteReader
'The following should get the file back to its original form'
buf = reader.GetValue(0)
'This is go into the Safe and retrieve file'
Dim datawrite As New System.IO.FileStream("Safe", IO.FileMode.Open, IO.FileAccess.ReadWrite)
datawrite.SetLength(0)
datawrite.Write(buf, 0, buf.Length)
datawrite.Close()
reader.Close()
Dim fileinput As New System.IO.FileStream("Safe", IO.FileMode.Open, IO.FileAccess.ReadWrite)
'specific file output location wiht proper extension'
Dim fileoutput As New System.IO.FileStream(Decrypt_TextBox.Text & "\" & filename, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
'The next line makes sure that the file is empty'
'Declaring variables for encryption'
Dim buffer(4096) As Byte 'Holds the bytes for processing
Dim BytesProcessed As Double 'running count for bytes that are processed'
Dim filelength As Double = fileinput.Length() 'Length of file coming in where intEnd will be greater than intStart'
Dim bytesinblock As Integer 'current bytes in block'
Dim crypto As CryptoStream
'Declaring crypto service provider'
Dim scRijndael As New System.Security.Cryptography.RijndaelManaged
'setting up progress bars
Encrypt_ProgressBar.Value = 0
Encrypt_ProgressBar.Maximum = 100
crypto = New CryptoStream(fileoutput, scRijndael.CreateDecryptor(key, IV), CryptoStreamMode.Write)
While (fileinput.Read(buffer, 0, 4096) > 0)
'reading the file'
bytesinblock = buffer.Length
'writing the file to cryptoStream'
crypto.Write(buffer, 0, bytesinblock)
'updating bytes processed'
BytesProcessed = BytesProcessed + CLng(bytesinblock)
'equation for updating bytes in block'
Decrypt_ProgressBar.Value = CInt((BytesProcessed / filelength) * 100)
End While
crypto.Close()
fileinput.SetLength(0)
fileoutput.Close()
fileinput.Close()
MessageBox.Show("File is done decrypting")
Decrypt_ProgressBar.Step = 0
Decrypt_ProgressBar.Value = 0
Decrypt_TextBox.Text = ""
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Return 1
I have no clue what I'm doing wrong here. It keeps saying that the file length is invalid for all lengths. I think its a problem with extracting from the database. The database type is Blob in SQLite. This is the only thing I need to complete to have this program done. Can anyone help?
|
|
|
|
|
Does anyone know what I'm doing wrong?
|
|
|
|
|
crain1981 wrote: It keeps saying that the file length is invalid
where? in which line?
crain1981 wrote: for all lengths
what does that mean?
|
|
|
|
|
No matter the file length it gives me this error. It does this at crypto.close(). I've googled around and still is...
|
|
|
|
|
I've also taken out the encryption and found out that the problem still exists without encryption.
|
|
|
|
|
A few statements:
1. I don't know why you are storing the file size; you sure don't need it to store or retrieve the file data.
2. If the crypto code is unhappy about the file size or file data, then the size or data are probably wrong and the problem is NOT in encryption.
3. As long as you fail to store and retrieve binary data, it makes no sense to complicate things with encryption/decryption.
First create methods that deal with arbitrary blobs; then add some methods that handles encryption. So start with a text file, think of it as binary data, store it in a blob, retrieve the blob, store it in a new file, and compare both files. And don't mix separate functions into a single method.
4. Don't create a bunch of code, and then discover it doesn't work; you are wasting your time. Write a small bit of code, and check it works absolutely fine. Then add some, test, fix, and repeat.
5. This has been going on since medio December; all it takes is four methods, each less than 20 lines of code.
6. Suggestion: if you need only one field, use ExecuteScalar.
|
|
|
|
|
1) I figured that out already
2) Pin pointed that problem
3) Never dealt with databases before
4) NEVER did that and have constantly repeated testing... I'm always encountering one error.
5) SMDH... I ain't even going to respond there.... this is different direction than before.
6) Thanks for the suggestion...
With little experience inserting into the database and no clue on how to extract the file is where my problem is.
|
|
|
|
|
Dear all,
I'm trying to do a project on birds and saving information such as the scientific classification and naming. I want to save images of birds in the database so I can display them later in forms or reports when the user does a query about a bird. For some birds I have more than one image so I want to include all images.
My question is how I can do that, I mean how can I store the images in oracle?
I'm using Oracle 9i. So far I have created a table to store the birds and their classification and tried to google about storing the images but no luck yet
Could you please help me with that..
I have a quite little background in oracle 9i :$
Thanks folks
|
|
|
|
|
noora-m wrote: tried to google about storing the images but no luck
I do wonder what you used as the serch criteria, I find pleanty of info with the following oracle 9i store images
If there are to be mode than 1 images per bird then you need a separate table for the images with a FK to the birds table.
BirdsTable
BirdID (PK)
BirdName
ImageTable
ImageID (PK)
BirdID (FK)
BlobField
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello,
All of a sudden we are experiencing poor performance on our DB server, something that would like 5 seconds is now taking 25 minutes are not completing the query. Checked the sql server logs, nothing.
Only difference is we have started to re-index all our indexes. We started this on Monday, and have schedules set up so that we have a few done every day. Does this hamper the performance? This is the first time the indexes are being re-indexed. Any ideas as where to look for SQL performance?
Thanks!
|
|
|
|
|
vanikanc wrote: Any ideas as where to look for SQL performance
SQL Profiler. Look in your start menu.
|
|
|
|
|
|
Hello,
About twice a month our sql server agent stops running all the jobs, till the server has been restarted. on checking the error log we found this message, approximately every 5 seconds in the log file till the time the server was re-started.
Message
[165] ODBC Error: 0, Memory allocation failure [SQLSTATE HY001]
It fails on this job that takes about 12 hours to run.
Any ideas on this error message?
Thanks.
|
|
|
|
|
This may be unrelated but check your maximum memory. We had a problem where sql server quit running and it was because the memory was set to the default which meant sql took all the memory and the OS had none.
|
|
|
|
|
Have a look at this[^]
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Hi,
I have a scheduled job set to run on server A, with 5 steps. One of the stored procs in this job, step 4 is taking a long time to complete, we moved it to another which does not take much time to execute. Now we are trying to change this step so it uses the other server B.
So on server A, I tried something like this -- exec serverB.database.dbo.sp_load_data.
This is not working. Is there a way to execute stored proc on another server?
Thanks!
|
|
|
|
|
It looks like you're using SQL Server so setting up a linked server on Server A should be all you need.
|
|
|
|
|
I am new to Linked servers.
If you have an article or some sort handy could you please post it.
Thanks so much for your time.
|
|
|
|
|
|
|
I see something set up for tables and view thru Linked servers.
I am using a stored proc. how would we do that?
|
|
|
|
|
Once the link is setup it can be called by
EXEC [linkedserver\instance].database.schema.sp I find it best to put [] around the linked part so I do not forget if I have a named instance (as shown).
|
|
|
|
|
I tried this.
Looks like RPC needs to be enabled on the remote server? is that the only way to go about?
|
|
|
|
|
I have a requirement that specifies that I need to block the access of a process to some records that are used by another process. This can be easily done by adding a Locked(bit) column and a ProcessID(int) column. The problem appears later in the specification when it says that in the case a process dies the rows locked have to be unlocked. The same must apply if the process is blocked in some way. Another problem is the fact that the login with which these processes run does not have VIEW SERVER STATE permission (nor it can be given that permission) so I can't use sysprocesses view or sp_who procedure.
Is there any way around this or another possible solution?
|
|
|
|
|
You fail to mention what db you are using.
If you use Oracle or DB2 you can Select for update...
There's a similar method for SQL server but it locks whole pages instead of records as far as I know.
"When did ignorance become a point of view" - Dilbert
|
|
|
|