on 07-17-2009 2:42 PM
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;
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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();
}
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.