on 01-07-2010 5:41 AM
Hi All
I have a problem in creation of table using SDK on a button event. I have a procedure to create tables and fields. If I call this procedure on a menu Event than it works fine but If I call this procedure on a button event than It gives error "Ref count for this object is higher than 0" . I know this error occur When an object does not release after creating a table. but this error occur at when first table is created. My code it given below. plz see and give me your valuable suggestions.
Dim oUserTablesMD As SAPbobsCOM.UserTablesMD
Try
oUserTablesMD = B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
oUserTablesMD.TableName = "AM_OBIN"
oUserTablesMD.TableDescription = "PutAway Table"
oUserTablesMD.TableType = BoUTBTableType.bott_Document
lRetCode = oUserTablesMD.Add
'// check for errors in the process
If lRetCode <> 0 Then
B1Connections.diCompany.GetLastError(lRetCode, sErrMsg)
MsgBox(sErrMsg)
Else
B1Connections.theAppl.StatusBar.SetText("Table: " & oUserTablesMD.TableName & " was added successfully", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success)
End If
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
oUserTablesMD = Nothing
GC.Collect()
'***************************************************************
oUserTablesMD = B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
oUserTablesMD.TableName = "AM_BIN1"
oUserTablesMD.TableDescription = "PutAway Upper Grid"
oUserTablesMD.TableType = BoUTBTableType.bott_DocumentLines
lRetCode = oUserTablesMD.Add
'// check for errors in the process
If lRetCode <> 0 Then
If lRetCode = -1 Then
Else
B1Connections.diCompany.GetLastError(lRetCode, sErrMsg)
MsgBox(sErrMsg)
End If
Else
B1Connections.theAppl.StatusBar.SetText("Table: " & oUserTablesMD.TableName & " was added successfully", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success)
End If
System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
oUserTablesMD = Nothing
GC.Collect()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Thanks
Regards
Gorge
Hi Gorge,
The "Ref count error..." usually occurs in case of Meta Data objects not being properly cleared. And yes, you have got the error in the right place, generally while creating tables / fields / UDOs. For this, you just need to clear the Meta Data object (At times even DI objects like Record Set) once they are used.
Eg: Release these objects in the below way in a Finally Block.
System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecordSet);
Hope this helps.
Regards,
Satish
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 Satish 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
Mr. John Chadwick, Info advised. But for more details.
While creating User Fields we will use two DI objects:-
1) Record Set for the purpose of exist field or not from CUFD table.
2) UserfieldMD Object for the purpose of create of field.
Major reason behind creating error on this :-
We were initialize Record Set Object simultaneously with UserFieldsMD.
Error Effect
-1120 Ref is higher than 0
Sol:-
if(oRS.RecordCount = 0) then
system,.Runtime,Interoperateservices.Marshal.Release.ComObject (oRS)
oRS =Nothing
GC.Collect()
oUDFMD = oCompany.GetBusinessObject(oUserFields)
oUDFMD.TableName= ""
oUDFMD.Name = ""
.
.
lretcode = oUDFMD.Add()
Repeat same steps of release com object code for OUDFMD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.