Solved

Very Strange Error Message in VB.NET App.

Posted on 2008-10-06
9
203 Views
Last Modified: 2012-05-05
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
Comment
Question by:Mr_Fulano
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22657080
I think you have a memory overrun... Are you crossing array boundaries.. i hope you are building dynamic SQL?
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22657088
wondering if you are dealing with sockets?
0
 

Author Comment

by:Mr_Fulano
ID: 22658519
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 13

Expert Comment

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

0
 

Author Comment

by:Mr_Fulano
ID: 22664615
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
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22666421
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
 

Author Comment

by:Mr_Fulano
ID: 22666493
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
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 500 total points
ID: 22666541
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
 

Author Comment

by:Mr_Fulano
ID: 22674036
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Extracting last characters in a substring 5 26
VB.NET 1 21
SqlServer no dupes 25 34
VB.net and sql server 4 33
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question