Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Very Strange Error Message in VB.NET App.

Hi, I am using VB 2005, WinForms.  During the creation of a SQL INSERT String for my database connection, I received the following error message at two different times.  The error is a bit cryptic and not something I had ever seen before. The message occurred both times as I clicked on the Form part of my application, where there are no controls. The last time it occurred, I had just set the SQL Insert String connections for two DateTimePickers I have on  the Form.  The connection for the DateTimePickers seems to be OK, because I can send data to the DB Table.

ERROR MESSAGE:
=====================================================================
HEAP[Main.exe]: HEAP: Free Heap block 1f1058 modified at 1f1098 after it was freed
Windows has triggered a breakpoint in Main.exe.

This may be due to a corruption of the heap, and indicates a bug in Main.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information
=====================================================================

I cannot reproduce this error each time the application runs. It seems to have gone away...

1). Does anyone have any idea what this means or what it could be due to? What type of corruption is the error message referring to? --- I'm able to run the App after I closed the App down, but I want to understand this error and address it before I move forward.

2). Could this have been as a result of a prior crash during debugging, which I did have a couple?

3). Would a TRY / CATCH / END TRY statement be advisable here? Or is this something else.

4). Could this be related to something else that was happening (or did happen) on my computer before, in another application or is this a VB problem?

Thanks,
Fulano
0
Mr_Fulano
Asked:
Mr_Fulano
  • 5
  • 4
1 Solution
 
SameerJagdaleCommented:
I think you have a memory overrun... Are you crossing array boundaries.. i hope you are building dynamic SQL?
0
 
SameerJagdaleCommented:
wondering if you are dealing with sockets?
0
 
Mr_FulanoAuthor Commented:
Hi SameerJagdale, I am not building dynamic SQL strings. I was using the DataAdapter and the CommandBuilder until I realized that I cannot use it with tables that are JOINED.  So, my only option is building my own SQL strings and commands.

What do you mean by "dealing with sockets"? If you give me an example, I can say yea or no.

Thank
Fulano
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SameerJagdaleCommented:
>> So, my only option is building my own SQL strings and commands.
Can you show me how you are doing this?

0
 
Mr_FulanoAuthor Commented:
Hi SameerJagdale, sorry for the delay, but I wanted to get you as much information as possible. I think I'm causing this problem myself.  This is what's happening. -- I'm trying to add a record to one of my database tables.  I've been using DataAdapter and CommandBuilder throughout my application and they've been working fine. However, one table is JOINED to other tables and when I tried to add a record to that table, I got the following error message:

>> An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
>> Additional information: Dynamic SQL generation is not supported against multiple base tables.

The code that caused this error is listed below:
Private Sub addNewItem()
'
Dim drNewRow As DataRow = m_dtItems.NewRow()
m_DBConnection.Open()
m_daDataAdapter.Fill(m_dtItems)
drNewRow("ItemName") = Trim(tbxItemName.Text)
drNewRow("ItemType") = Trim(tbxItemType.Text)        
drNewRow("ItemPrice") = Trim(tbxItemPrice.Text)
m_dtItems.Rows.Add(drNewRow)
m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
m_daDataAdapter.Update(m_dtItems)            <<< The error happens here...
m_DBConnection.Close()
End Sub

I then posted a question here on EE and got some good help from one of the Experts. The code that he helped me compose is below:

Private Sub addNewItem()
'
Dim SQLString As String
SQLString = "INSERT INTO Items (ItemName, ItemType, ItemPrice) VALUES (Items.ItemName, Items.ItemType , Items.ItemPrice)"
'
Dim cmd As New OleDb.OleDbCommand(SQLString, m_DBConnection)
cmd.Parameters.Add("Items.ItemName", OleDb.OleDbType.VarChar, 50, Trim(tbxItemName.Text))
cmd.Parameters.Add("Items.ItemType", OleDb.OleDbType.VarChar, 50, Trim(tbxItemType.Text))
cmd.Parameters.Add("Items.ItemPrice", OleDb.OleDbType.Currancy, Trim(tbxItemPrice.Text))
m_DBConnection.Open()
cmd.ExecuteNonQuery()
m_DBConnection.Close()
End Sub

This worked well, but then the HEAP problem emerged. I think that since I'm using DataAdapeter elsewhere on this Form with this table (to read from it), I am introducing the problem when I use the second approach.

Do you think this is the reason I'm getting the HEAP error? Also, do you have any suggestions on how I can go back to using my original approach with DataAdapter and avoid the error it was causing?

Thanks,
Fulano
0
 
SameerJagdaleCommented:
well, as i had mentioned earlier
>>i hope you are building dynamic SQL?
in one of my comments, this can definitely be an issue. however, you haven't mentioned if you are still getting the error!
what interests me more in your first approach is you are using commandbuilder and i cannot find the selectcommand for dataadapter..hence, when you try to update the dataadapter, it will have an emplty updatecommand (which gets generated if selectcommand is set)..and may throw an exception..my thought :-)
thanks
Sameer
0
 
Mr_FulanoAuthor Commented:
Hi Sameer, the reason I do not have a SELECT command is that the DataTable (m_dtItems) is declared at the module level and is loaded in the Form's Load Event. So, by the time I use it in my addNewItem() method, it is already filled with records. I do however agree with you that the command builder will be looking for a SELECT statement. However, that's not the error I was getting. I was getting an error that stated: "Dynamic SQL generation is not supported against multiple base tables."  Hence, it didn't like the fact that I had JOINed tables.

Any thoughts...?
Fulano
0
 
SameerJagdaleCommented:
Fulano,
The issue is with the CommandBuilder object as It works only for tables without any joins. the reason being it may have difficult generating update, insert and delete
commands for joined tables.
the workaround would be to write your own update command da.UpdateCommand.CommandText = "your update command"
or you can very well make use of stored procs, dynamic sqls are sometimes pain.
Thanks
-Sameer
 
0
 
Mr_FulanoAuthor Commented:
Hi Sameer, I think I was able to solve the problem. I'm updating one table at a time and I created a new SELECT command for my addNewItem() method. Regardless, I appreciate your help and I did learn a couple of things along the way. Also, the error has not occurred again.

Thanks,
Fulano
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now