cancel
Showing results for 
Search instead for 
Did you mean: 

UDT -1120 "Ref count for this object is higher than 0"

Former Member
0 Kudos

Hi,

I am inserting new table and I get error -1120 "Ref count for this object is higher than 0"

I have read following ticket: []

But I get the error on my first Table???

The code is below.

Thank you,

Rune


SAPbobsCOM.UserTablesMD oUserTablesMD = (SAPbobsCOM.UserTablesMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);

                oDataTable_TABLE = o_DataSet_XML_UdtUdfData.Tables["TableName"];

                vm_ROW_Count_int = oDataTable_TABLE.Rows.Count - 1;

                for (vm_ROW_Counter_int = 0; vm_ROW_Counter_int <= vm_ROW_Count_int; vm_ROW_Counter_int++)
                {
                    o_DataRow_TABLE = oDataTable_TABLE.Rows[vm_ROW_Counter_int];
                    oUserTablesMD.TableName = o_DataRow_TABLE["Name"].ToString();
                    oUserTablesMD.TableDescription = o_DataRow_TABLE["Description"].ToString();

                    if (oUserTablesMD.TableName != "")
                    {
                        vm_Error_Message_string = "Import of Table Failed: " + o_DataRow_TABLE["Name"].ToString();

                        vc_ADD_MessageNumberResult_Int32 = oUserTablesMD.Add();

                        if (vc_ADD_MessageNumberResult_Int32 == 0)
                        {
                            #region Log Import of Table Sccessed 
                            

                            #endregion
                        }
                        else
                        {
                            #region Log Import of Table Failed

                            oCompany.GetLastError(out vmp_B1_Error_Code_int, out vmp_B1_Error_Message_string);
                            string Test = vmp_B1_Error_Message_string;

                            #endregion
                        }
                    }
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
                oUserTablesMD = null;

Accepted Solutions (1)

Accepted Solutions (1)

Nussi
Active Contributor

Hi Rune,

first of all

you forgot to use

GC.Collect()

in your code

System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);

oUserTablesMD = null;

GC.Collect();

also creating fields before can lock the adding process of tables.

that means: look if you create fields before in SAP tables and you didnt cleanup using the above code sample

lg David

Former Member
0 Kudos

Nice...

So I should run this code before and after to be on the right side?

System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
oUserTablesMD = null;
GC.Collect();

Nussi
Active Contributor
0 Kudos

Rune,

usually you run this code in the end of a procedure or function.

personally the best place for me is the finally part of a try catch


SAPbobsCOM.UserTablesMD oUserTablesMD = (SAPbobsCOM.UserTablesMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);
 
try
{

} catch
{

}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
oUserTablesMD = null;
GC.Collect();

}

btw - also open recordsets in previous code can lock the adding process of fields and tables.

lg David

Former Member
0 Kudos

Nice...but I get the error in the start of my method...so it is not clean when I start...

edy_simon
Active Contributor
0 Kudos

Hi Rune,

Before this procedure, did you create any meta data object ?

After creation of any meta data object, your object must be disposed off properly. Otherwise, when you try to create another meta data object, this error will be raised.

Regards

edy

Former Member
0 Kudos

Which object is in the meta data object?

And is it the same code i have to run as meantion earlier?

System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD);
oUserTablesMD = null;
GC.Collect();

Thank you very much of your feedback

edy_simon
Active Contributor
0 Kudos

Hi rune,

I mean, in your code, before this procedure, is there any other procedure creating a UDF / UDT / UDO ?

If yes, then in each of the procedure, you have to dispose the object by the code you quote.

Regards

Edy

Former Member
0 Kudos

No, that's the problem...this is the Init of my Add-On...

Why can I not clean up before; instead of expecting people to run the present code before me...???

I do not want to clean up after other people...

Edited by: Rune Brattas on Jul 17, 2009 7:56 PM

Former Member

Hi Edy,

You are right...

I did a DoQuery and it ruin my code later on...

Here is my trouble code and the fix:

...I like to clean up after me...

Thank you,

Rune


oRecordset = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                try
                {
                    oRecordset.DoQuery("SELECT ...I am checking if the table exist...");
                }
                catch
                {
                    return true; // The Table do not exist...
                }
                finally
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecordset);
                    oRecordset = null;
                    GC.Collect();
                }

Answers (2)

Answers (2)

Former Member
0 Kudos

Re: GC.Collect()

Does the B1 SDK sufficiently obfuscate the automatic garbage collection to render advice given in places like here (http://stackoverflow.com/questions/118633/whats-so-wrong-about-using-gc-collect) or here(http://stackoverflow.com/questions/478167/when-is-it-acceptable-to-call-gc-collect) obsolete? If so, can someone explain to me how SAP does this?

Former Member
0 Kudos

Your answer is correct EDY but you know this errors are dependent on certain conditions, like mine i already released the objects i was using but still got error, but what i realised was that because i was using probably the same UDF & UDO as a prexexisting table i deleted, i was getting the ref. count is greater than zero. So what i did was go into the search for the existing reference to the already deleted table in OUTB and CUFD with this:=

select T0.*, t1.* from OUTB T0 inner join CUFD T1 on '@'+T0.TableName = T1.TableID

where T1.TableID = '@tableFieldName' order by T1.TableID

select T0.*, t1.* from OUTB T0 inner join CUFD T1 on '@'+T0.TableName = T1.TableID

where T1.TableID = '@TableName' order by T1.TableID

and deleted it with this query

USE [SBODemoUS]

GO

DELETE FROM OUTB

      WHERE TableName = @tableFieldName'

DELETE FROM CUFD

      WHERE TableID = '@TableName'

DELETE FROM OUTB

      WHERE TableName = '@TableName'

DELETE FROM CUFD

      WHERE TableID = '@tableFieldName'

GO

This solved my Ref. count issue.....Hope this helps someone......Thanks

Kind Regard

Oluwatosin Akinnifesi| Technical Consultant

Email: tosin@streadit.com

Website: www.streadit.com