This error is displayed when trying to open or close a window with a .NET addin on it. It is usually followed my the error
BAD_MEM_HANDLE
or simply the dreaded "The application has to close" error
Then GP crashes.
The causes are data buffer related. Either there is a table buffer that has been opened in .NET that has not been closed, or a reader has not been closed.
The reader error can be hard to detect when reading the code. For example, the following code will result in the reader being left open.
OdbcDataReader reader = oCmd.ExecuteReader();
if (reader.Read())
{
return reader.GetString(0);
}
else
{
return string.Empty;
}
The reader can't be closed before the return statement, since the reader is needed for the return value.
To fix it, we have the take the long way around and store the return value before closing the reader.
OdbcDataReader reader = oCmd.ExecuteReader();
string result = "";
if (reader.Read())
{
result = reader.GetString(0);
}
else
{
result= string.Empty;
}
if (!reader.IsClosed)
{
reader.Close();
}
return result;
So the lesson learned here is that when working with readers, it is a good idea to store your reader results and close the reader before operating on them.. That way you won;t try to take a shortcut like the first example.
Did this help you? If so, please leave a comment!
David Jedziniak maintains this blog and posts helpful tips and tricks on SQL Server and Dynamics GP development. The opinions expressed here are those of the author and do not represent the views, express or implied, of any past or present employer. The information here is provided without warranty of fitness for any particular purpose.
Subscribe to:
Post Comments (Atom)
SQL 2022 TSQL snapshot backups!
SQL 2022 now actually supports snapshot backups! More specifically, T-SQL snapshot backups. Of course this is hardware-dependent. Here ...
-
If you are reading this, you are probably aware of the fact that you cannot deploy SSRS 2008 reports on an SSRS2005 server. SSRS reports ar...
-
SQL Job to refresh TEST from PRODUCTION Last Updated: 2018.11.12 I like to include each of these steps as a separate job step. If you ...
-
I ran into an issue today where I had a report parameter default that I couldn't seem to get rid of. In BIDS, I deleted the defaults f...
No comments:
Post a Comment