Error when query table from custom database

Hi all,

I have a custom database(not company database) to store information to be retrieve by all companies in a custom form. I am able to query its table using plain query in MSSQL Management Studio.

With Sage 200, I am able to make a connection to the database using Sage.ObjectStore.ConnectionData. I make persistent object class for the tables in custom database using Sage 200 ObjectStore Builder.

But not able to add or select from its table due to "Sage.ObjectStore.DatabaseException: Counter Table is missing or corrupt ---> Sage.ObjectStore.MissingTableException: Counter Table is missing or corrupt". 

Full error as below. 

Sage.ObjectStore.DatabaseException: Counter Table is missing or corrupt ---> Sage.ObjectStore.MissingTableException: Counter Table is missing or corrupt
   at Sage.ObjectStore.Counter.GetPage(Int32 pageSize)
   at Sage.ObjectStore.PrimaryKeyGenerator.get_NextPrimaryKey()
   at Sage.ObjectStore.PersistentObject.GenerateNextPrimaryKey()
   at Sage.ObjectStore.Database.GetInsertCommand(IDbCommand dbCommand, List`1 parameters, IDatabaseObject src, List`1 fields, String tableName, Field primaryKeyField)
   at Sage.ObjectStore.Database.Insert(IDatabaseObject src, List`1 fields, String tableName, Field primaryKeyField)
   --- End of inner exception stack trace ---
   at Sage.Common.Exceptions.ExceptionManager.Throw(Exception e)
   at Sage.ObjectStore.Database.Insert(IDatabaseObject src, List`1 fields, String tableName, Field primaryKeyField)
   at Sage.ObjectStore.Database.Insert(IDatabaseObject src)
   at Sage.ObjectStore.PersistentObject.AddNewPrivate()
   at Sage.ObjectStore.PersistentObject.AddNewInternal()
   at Sage.ObjectStore.PersistentObject.AddNew()
   at Sage.ObjectStore.PersistentObject.Add()

Is Sage.ObjectStore.PersistentObject can only be use if we are in the company database?

Parents
  • 0

    Another possibility is to set your own primary key (if you have some way of generating them), This can be done by defining the primary key like this:

        Private _MyTableDbKey as Field
    <Builder.MetaDataField(ColumnName:="MyTableID", IsPrimaryKey:=True, IsIndexed:=True, IsUnique:=True, DbType:=DbType.Int64)>
    Property MyTableDbKey As Sage.Common.Data.DbKey
    Get
        Return _MyTableDbKey.GetDbKey
    End Get
    Set
        _MyTableDbKey.Value = Value
    End Set
    End Property
    

    then overriding UpdateInternal:

    Protected Overrides Sub UpdateInternal()
    	'allow primary key to be set
    	If Not Me.IsNew OrElse Me.PrimaryKey.IsNull Then
    		MyBase.UpdateInternal()
    	Else 'add new record with specific primary key
    		Using tran As New PersistentObjectTransaction(Me)
    			InvokeMethod(GetProperty(Me, "Database"), "Insert", Me)
    			tran.Commit()
    		End Using
    	End If
    End Sub

    (InvokeMethod and GetProperty are simple reflection routines)

Reply
  • 0

    Another possibility is to set your own primary key (if you have some way of generating them), This can be done by defining the primary key like this:

        Private _MyTableDbKey as Field
    <Builder.MetaDataField(ColumnName:="MyTableID", IsPrimaryKey:=True, IsIndexed:=True, IsUnique:=True, DbType:=DbType.Int64)>
    Property MyTableDbKey As Sage.Common.Data.DbKey
    Get
        Return _MyTableDbKey.GetDbKey
    End Get
    Set
        _MyTableDbKey.Value = Value
    End Set
    End Property
    

    then overriding UpdateInternal:

    Protected Overrides Sub UpdateInternal()
    	'allow primary key to be set
    	If Not Me.IsNew OrElse Me.PrimaryKey.IsNull Then
    		MyBase.UpdateInternal()
    	Else 'add new record with specific primary key
    		Using tran As New PersistentObjectTransaction(Me)
    			InvokeMethod(GetProperty(Me, "Database"), "Insert", Me)
    			tran.Commit()
    		End Using
    	End If
    End Sub

    (InvokeMethod and GetProperty are simple reflection routines)

Children