cancel
Showing results for 
Search instead for 
Did you mean: 

err 1120 Ref Count > 0 ..... Not sure why as it is the first thing I do

Former Member
0 Kudos

the Process once I have connected with the company is to first check existance of a UDF in the ORDR table

if it is not there I call the following function

using

createUDF("U_UpldDte", "Upload Flag", "ORDR")

but it always fails with :

Ref count for this object is higher then 0

I have tried using the

UserFields object and the UserFieldsMD but with no success,

The Ocompany object is global,

releasing the object prior to use does not help.

The frustrating thing is that I have met this problem b4 and was able to get past it but due to a hard drive failure (dont ask!!! ) I lost that particular piece of code...


   Public Shared Function createUDF(ByVal UDFName As String, ByVal UDFDescription As String, ByVal UDFTable As String) As String
            Dim RetVal As Long
            Dim ErrCode As Long
            Dim ErrMsg As String
            Dim ErrorMsg As String
            Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
            Try
                oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
                GC.Collect()
                oUserFieldsMD = Nothing
                oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
                With oUserFieldsMD
                    .TableName = UDFTable
                    .Description = UDFDescription
                    .Name = UDFName
                    .Type = SAPbobsCOM.BoFieldTypes.db_Alpha
                    .EditSize = 10
                End With

                RetVal = oUserFieldsMD.Add
                If RetVal <> 0 Then
                    oCompany.GetLastError(ErrCode, ErrMsg)

                    ErrorMsg = ErrCode & " " & ErrMsg

                End If
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
                oUserFieldsMD = Nothing
                GC.Collect()
            Catch ex As Exception
                createUDF = "ERROR: Unable to create " + UDFName + " In " + UDFTable + ex.Message
                Exit Function
            End Try
        End Function

Accepted Solutions (1)

Accepted Solutions (1)

former_member184566
Active Contributor
0 Kudos

Hi George Savery

The reason it is doing this is because you have more than one meta data object active. You must use UserFieldsMD, the md stands for meta data. Before calling this procedure you must have no other meta data objects open that have not been released. In your code here, at the bottom you release the object, perfect. But do you have any others you have not done this to??? Is there a recordset that you used before calling this??? If so, close it.

Hope this helps

Former Member
0 Kudos

spot On Louis.

I used an


 oOrders = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)

to use when looking to see if the UserField existed when I added the lines


  System.Runtime.InteropServices.Marshal.ReleaseComObject(oOrders)
            oOrders = Nothing
            GC.Collect()

the Error dissappeared.

(pls excuse the 'verbosenes' as I dont want to spend another day trying to figure this out

Thanks Again!!!!

former_member184566
Active Contributor
0 Kudos

Not a problem

Answers (0)