|
On executing of this line
br.Read(bytBuffer, 0, bytBuffer.Length)
We are trying to read a binary files of size 88kb , and merge all these into a single file , sometimes the application crashes on br.Read statement.
We later found out that it is a system error &H80131315& .
How can we solve this ??
|
|
|
|
|
If you put a Try..Catch block around the read does it give you more information?
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
melvis_vaz wrote: br.Read(bytBuffer, 0, bytBuffer.Length)
My guess is that you are over-running the buffer or have not properly initialized it. As has been suggested already, encapsulate this in a Try..Catch block and extract more information from the thrown exception.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
Dim bw As BinaryWriter
Dim br As BinaryReader
Dim lFileSize As Long
Dim bytBuffer() As Byte = New Byte() {}
Dim sOutputPath As String = sFilePath.Substring(0, sFilePath.Length - 4)
Dim fsInput As New FileStream(sFilePath, FileMode.Open, FileAccess.Read)
Dim fsOutput As New FileStream(sOutputPath, FileMode.Create, FileAccess.ReadWrite)
Try
br = New BinaryReader(fsInput)
br.BaseStream.Seek(0, SeekOrigin.Begin)
lFileSize = FileSize(sFilePath)
ReDim bytBuffer(lFileSize - 1)
br.Read(bytBuffer, 0, bytBuffer.Length)
Dim MaxOut As Int32 = lFileSize - 64
ReDim btyBufferOutput(MaxOut - 1)
Dim Status As Int32 = 0, RetVal As Int32 = 0, Progress As Int32 = 0
Do
RetVal = CryptStatus(Status, Progress)
Loop While ((RetVal = 0) And (Status = 2))
bw = New BinaryWriter(fsOutput)
bw.Write(btyBufferOutput)
fsOutput.Flush()
br.Close()
fsInput.Close()
fsOutput.Close()
bw.Close()
Catch ex as Exception
Msgbox(ex.ToString)
Finally
fsOutput = Nothing
bw = Nothing
br = Nothing
fsInput = Nothing
End Try
This is the code . We have put try , catch . Also properly initialized it.
|
|
|
|
|
Where do you declare btyBufferOutput? Why do you output the contents of btyBufferOutput without putting anything in it?
---
b { font-weight: normal; }
|
|
|
|
|
The actual code is :
Dim bw As BinaryWriter
Dim br As BinaryReader
Dim lFileSize As Long
Dim bytBuffer() As Byte = New Byte() {}
Dim btyBufferOutput() As Byte = New Byte() {}
Dim sOutputPath As String = sFilePath.Substring(0, sFilePath.Length - 4)
Dim fsInput As New FileStream(sFilePath, FileMode.Open, FileAccess.Read)
Dim fsOutput As New FileStream(sOutputPath, FileMode.Create, FileAccess.ReadWrite)
Try
br = New BinaryReader(fsInput)
br.BaseStream.Seek(0, SeekOrigin.Begin)
lFileSize = FileSize(sFilePath)
ReDim bytBuffer(lFileSize - 1)
br.Read(bytBuffer, 0, bytBuffer.Length)
Dim MaxOut As Int32 = lFileSize - 64
ReDim btyBufferOutput(MaxOut - 1)
' DecryptBuffer() function is decrypting the value in bytBuffer and
' storing the decyrpted value in bytBuffer output. this is calling a third- ' party dll
DecryptBuffer(sLangaugeKey, bytBuffer, lFileSize, btyBufferOutput, MaxOut)
Dim Status As Int32 = 0, RetVal As Int32 = 0, Progress As Int32 = 0
Do
RetVal = CryptStatus(Status, Progress)
Loop While ((RetVal = 0) And (Status = 2))
bw = New BinaryWriter(fsOutput)
bw.Write(btyBufferOutput)
fsOutput.Flush()
br.Close()
fsInput.Close()
fsOutput.Close()
bw.Close()
Catch ex as Exception
MsgBox(ex.ToString)
Finally
fsOutput = Nothing
bw = Nothing
br = Nothing
fsInput = Nothing
End Try
|
|
|
|
|
I don't know if this is the reason for the error, but it's worth trying:
Don't use ReDim. There is no way of resizing an array in .NET anyway, so there is no reason to use it. Just create the arrays when you know how large it needs to be:
bytbuffer = New Byte(lFileSize)
btyBufferOutput = New Byte(MaxOut)
---
b { font-weight: normal; }
|
|
|
|
|
Try obtaining the file size and hence the buffer length by this code...
Dim fileDetails As System.IO.FileInfo = New System.IO.FileInfo(sFilePath)
lFileSize = fileDetails.Length
That will give you the filesize in bytes. I think the FileSize() property you were using returned the size in kB (??).
Trace the code in debug mode and see that the filesize is what's expected. Inspect all other variables for correctness before each line is executed and you'll find the problem.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
In the code shown ,
lFileSize = FileSize(sFilePath)
'This function is used to get the filesize
Public Function FileSize(ByVal sFileName As String) As Long
Dim fileInfo As System.IO.FileInfo
fileInfo = New FileInfo(sFileName)
Return fileInfo.Length
fileInfo = Nothing
End Function
MV
|
|
|
|
|
So... have you traced the code? What was the value for the returned filesize? Is it valid etc...?
Just giving me more code without explanation or not answering my previous questions ain't gonna get you anywhere fast.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
-- modified at 7:27 Wednesday 11th January, 2006
|
|
|
|
|
The returned filesize is 88kb . We have encrypted binary files, we are reading this encrypted file into a buffer , and passing this buffer to dencryptbuffer() function. this is a 3rd party dll function which dencrypt the data from the buffer and stored in a output buffer.Then we are writing this output buffer to create dencrypted file.
The application works fine 4 times, but on the fifth time, the application crashes on BinaryReader.Read.
MV
|
|
|
|
|
melvis_vaz wrote: we are reading this encrypted file into a buffer , and passing this buffer to dencryptbuffer() function.
Ok, so it may be the decrypt function that's stuffing it up? Especially since you say it works the first 4 of 5 times that it's run.
Are you passing in the SAME buffer each time? Does the decrypt function destroy the input buffer in any way? Have you traced the code through five times and seen what's different on the fifth attempt?
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
The decrypt function is in a for loop and we are using Redim for the buffer , so it is intialized everytime. As the decrypt function is present in a 3rd party DLL , we do not know whether the decrypt function destroy the input buffer in any way.
MV
|
|
|
|
|
melvis_vaz wrote: The decrypt function is in a for loop and we are using Redim for the buffer , so it is intialized everytime
Not quite true. See previous posts re: ReDim(). There is no guarantee that the contents of the buffer have been zeroed.
melvis_vaz wrote: As the decrypt function is present in a 3rd party DLL , we do not know whether the decrypt function destroy the input buffer in any way.
Yes you do! That's what the debug trace is for. You inspect the buffer before and after each call to the decrypt function and see if it changes. Have you done this as I have been suggesting for the last three posts?
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
Hi guys,
I wanted to know how do we access a specific exe's instance from class library dll or any application.
The description of problem domain is as follows :
I have one VB.NET exe application which has certain functionality in it in classes. There are several instances of the same exe running in memory. I want to access specific instance and create instance of class in the exe from another client application.
Could you suggest a way to do it...
Thanks & Regards,
Birendra
Birendra
|
|
|
|
|
Input string was not in a correct format.
Line 94 seems to be the culprit but I don't know why
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 92: SqlConnection1.Open()
Line 93: Dim dreader As SqlClient.SqlDataReader
***********************************************************************
***********************************************************************
Line 94: dreader = cmdCategoriesById.ExecuteReader(CommandBehavior.SingleRow)
**********************************************************************************
**********************************************************************************
Line 95: If dreader.Read() Then
Line 96: txtCategoryName.Text = dreader(1)
Source File: c:\inetpub\wwwroot\VBNetUnleashed\WebApplication3\WebForm1.aspx.vb Line: 94
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
WebApplication3.WebForm1.ddlCategoryID_SelectedIndexChanged(Object sender,
EventArgs e) in c:\inetpub\wwwroot\VBNetUnleashed\WebApplication3\WebForm1.aspx.vb:94
System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()
Here is my code:
Private Sub ddlCategoryID_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddlCategoryID.SelectedIndexChanged
Dim categoryid As String
categoryid = ddlCategoryID.SelectedItem.Text
cmdCategoriesById.Parameters("@categoryid").Value = categoryid
SqlConnection1.Open()
Dim dreader As SqlClient.SqlDataReader
dreader = cmdCategoriesById.ExecuteReader(CommandBehavior.SingleRow)
If dreader.Read() Then
txtCategoryName.Text = dreader(1)
txtCategoryDescription.Text = dreader(2)
End If
dreader.Close()
SqlConnection1.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSave.Click
With cmdCategoriesUpdate
.Parameters("@categoryid").Value = ddlCategoryID.SelectedItem.Text
.Parameters("@categoryname").Value = txtCategoryName.Text
.Parameters("@categorydescription").Value = txtCategoryDescription.Text
End With
SqlConnection1.Open()
cmdCategoriesUpdate.ExecuteNonQuery()
SqlConnection1.Close()
End Sub
End Class
|
|
|
|
|
The category id could not be converted to a number.
You should convert the values to the correct data type before putting them in the parameters. Also, you should specify the data type of the parameters, or the command object has to ask the database for the data types. This causes an extra round trip to the database.
---
b { font-weight: normal; }
|
|
|
|
|
I am lost, still not sure what values I need to correct to the right data type?
|
|
|
|
|
You have to make sure that the category id value can be converted to a number. If there is a possibility that it's not a number, use Double.TryParse to parse the string.
---
b { font-weight: normal; }
|
|
|
|
|
Where do I use that double.tryparse?
Where is that put in the code
|
|
|
|
|
Now you are getting the string from the form field, then putting the string into the parameter. After you have gotten the string, try to parse it. If the parsing was successfull, you can continue by converting the double to an int (as I assume that is the datatype in the database) and put it in the parameter.
If the parsing fails, you can either set the value to a default value, or display an error message.
---
b { font-weight: normal; }
|
|
|
|
|
hi all
i had made the database project in vb.net and access. now i want that my
software should generate the reports how to do that any software required for
the report generation. or what i want is take the data from data base and generat report.
ddd
|
|
|
|
|
Hi,
You can use Crystal Report for this.
Or if you dont have any Crystal Report software then. Open a dataset in vb.net and fill it up with the required data after giving search parameter. Now create programatically a text file(.txt) and write the out put from the query into that text file. that will solve your problem of reporting
DD
Debasish Das(MBA), is a hardcore software solution provider, working in ESSPL (INDIA). Got 5 years of experience on various client server technologies like Visual Basic,.NET framework, Power Builder, Message Queue Server. And also posses sound knowledge in Quality Processes applied to software engineering. Quite often travels overseas to provide solutions to some fortune 100 clients.
He can be reached with mr_debasishdas@hotmail.com or debasishd@esspl.com
|
|
|
|
|
I'm sorry, again, for this noobs question.
I'm using Visual Stuido 2005 and I was trying to insert a data to database.
This is how I do it so far.
1. Set the dataset ( Ms. Access database ), which results are PlasmaDBDataSet and UserTableAdapter
2. From PlasmaDBDataSet, I drag UserID field to my windows form, resulting UserIDTextBox and UserBindingNavigator, and codes :
<br />
Public Class MasterUserForm<br />
<br />
Private Sub UserBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UserBindingNavigatorSaveItem.Click<br />
<br />
Me.Validate()<br />
Me.UserBindingSource.EndEdit()<br />
Me.UserTableAdapter.Update(Me.PlasmaDBDataSet.User)<br />
<br />
End Sub<br />
<br />
Private Sub MasterUserForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
'TODO: This line of code loads data into the 'PlasmaDBDataSet.User' table. You can move, or remove it, as needed.<br />
Me.UserTableAdapter.Fill(Me.PlasmaDBDataSet.User)<br />
<br />
End Sub<br />
End Class
When running the program, I already can add new records and also navigate through all the records. The problem is the records werent save to my access database. I've try to add Me.PlasmaDBDataset.AcceptChanges() but still dont work.
I do search the MSDN but it say nothing more or less, just like that. Please kindly help me with this.
Thank you
WiL
|
|
|
|
|
A dataset is a disconnected view of the databaswe. Once you've made changes, you need to, seperately, connect back to your database and pass them through. There is at least one excellent article on doing this with access in C# on codeproject, I recommend searching the site.
Christian Graus - Microsoft MVP - C++
|
|
|
|