Solved

Very Strange Error Message in VB.NET App.

Posted on 2008-10-06
9
199 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now