Hi,
Owen, your suggestion is what we are already doing. In fact, we have a CreateTable function that incorporates it so that it is done every time we create a table in Business One.
John, I added your idea so that when that function declares the oUserTablesMD object, it is immediately set equal to nothing. No help.
Gianluigi, I added code to set the oUserTablesMD to Nothing before starting anything. No help.
I need to describe when it is the error appears. We run the same code during the start up of our add-on if the database doesn't already have a table. During the startup, the code tries to add all the tables any way just to make sure they all are there; so we expect to get the -2035 error for the tables already there and we do. However, we have situations where we need to force the add-on to go through the database initiation process during add-on development. I usually do this by changing a line of code in the add-on startup so that the code runs. This has always worked. However, there are times when we need to allow the user to force a database init. That means that the add-on is already running. We added a button to the add-ons options form do this. The error message only appears on the first time this button is clicked. If you click it a second time, the process runs without a hitch. In fact, you can click it many times and it works. Its only on the first time that it gives this message. In addition, the process tries to add about ten tables; it is only on the first table that it fails. The statement that gets the error is the oCompany.GetLastError function. It appears that the oCompany object is confused the first time around about which object had the last error. One more piece of information is that because we have more than one add-on, we created a class library for code that is common among them. The function that creates the table is in that library. At add-on startup, the librarys company object is set equal to the same company that the add-on is connected to. But again, we get no error at startup.
Any ideas?
Thanks,
Mike
Hi Mike,
Are you garbage collecting any previous instance of the UserTableMD or UserFieldMD objects? The 'reference count' error normally occurs if a previous instance is still in memory.
Try something like the following after you create each table or field:
System.Runtime.InteropServices.Marshal.ReleaseComObject(myObject)
myObject = Nothing
GC.Collect()
Kind Regards,
Owen
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.
Add a comment