Solved

Very Strange Error Message in VB.NET App.

Posted on 2008-10-06
9
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET/VB: Convert Date and Time to YYYY-MM-DDTHH:MM:SS 3 51
Best book for Internet security 4 55
Read top line from CSV file 14 60
VB .net 2010 Byte array 2 24
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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