# Exception: This service instance has not been activated yet

**URL:** https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065
**Category:** Remoting SDK
**Tags:** net, delphi
**Created:** [November 3, 2023, 3:06pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065 "2023-11-03T15:06:17Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 3, 2023, 3:06pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/1 "2023-11-03T15:06:17Z")

</div>

We very sporadically get this exception when calling DataAbstract GetData in our .NET RO/DA service (windows service).

What could cause this? How can we fix this?  
Simply restarting the service fixes the issue.

The full error callstack is

```auto
GetData/)| executed in 18,9912ms and returned Exception:RemObjects.SDK.Exceptions.ServiceInstanceNotActiveException: This service instance has not been activated yet.
   bij RemObjects.SDK.Server.Service.InternalGetSession(Boolean throwException)
   bij Officinall.BaseClasses.SQLLogger.createSQLCommand(String operationName, SQLEntry& sqlentry, Boolean bFinishExpected)
   bij Officinall.BaseClasses.SQLLogger.logDatabaseCommand(IDbCommand command)
   bij RemObjects.DataAbstract.Schema.BeforeExecutingGetDataReaderEventHandler.Invoke(ServiceSchema sender, BeforeExecutingGetDataReaderEventArgs e)
   bij RemObjects.DataAbstract.Schema.ServiceSchema.GetDataReader(IAbstractConnection connection, SchemaDataTable table, String[] dynamicSelect, XmlNode dynamicWhere, Boolean validateDynamicWhere, String[] parameterNames, Object[] parameterValues, SchemaColumnMappingCollection& columnMappings, IDbCommand& command)
   bij RemObjects.DataAbstract.Server.DataAbstractService.GetDataViaTableRequestFromPlainTable(SchemaDataTable tableSchema, TableRequestWrapper requestInfo, DataStreamer streamer)
   bij RemObjects.DataAbstract.Server.DataAbstractService.GetDataViaTableRequest(String tableName, TableRequestWrapper requestInfo, DataStreamer streamer, Boolean allowPrivateAccess)
   bij RemObjects.DataAbstract.Server.DataAbstractService.InternalGetData(String[] tableNames, TableRequestInfo[] requestInfo, DataStreamer streamer, Boolean allowPrivateAccess)
   bij RemObjects.DataAbstract.Server.DataAbstractService.GetData(String[] tableNames, TableRequestInfo[] requestInfo)
   bij OffNetServer.DataAbstract.OffNetDataAbstractService.GetData(String[] aTableNameArray, TableRequestInfo[] aTableRequestInfoArray)

```

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [November 3, 2023, 4:18pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/2 "2023-11-03T16:18:25Z")

</div>

> [@fvancrae](#):
>
> This service instance has not been activated yet.

Hm, I could see this happening if the service accesses the session before it has finished going the the Activate().

When request comes in, a your class factory is asked for a new or existing instance, and class ActivateInstance on that, then ir tuts the service call, and then Deactivates it. ServiceInstanceNotActiveException is thrown when trying to access the session on a service instance that has not been activated (or has been deactivated again).

What server channel and class factory are you using?

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 3, 2023, 4:48pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/3 "2023-11-03T16:48:22Z")

</div>

It’s a TCP channel, the client (delphi) and server (.net) are on the same LAN

No class factory is specified for the our DA service (it inherits from DataAbstractService)  
Note: This DA service can dynamically load the schema file, could that be related to the issue?

Some code snippets below

channel creation snippet:  
server.NetworkServer.ServerChannel = new RemObjects.SDK.Server.IpTcpServerChannel();  
server.NetworkServer.Port = 7789;  
int maxMesSize = int.MaxValue;  
BinMessage message = new BinMessage();  
message.MaxMessageSize = maxMesSize;  
message.MaxDecompressedMessageSize = maxMesSize;  
server.NetworkServer.RegisterServerMessage(message);  
server.Run(args);

schema loader snippet:  
var schemaLoader = new SchemaLoader(“genericdb.daSchema”);  
var container = new SimpleContainer();  
container.RegisterSDK(server.NetworkServer);  
container.RegisterDataAbstract();  
container.RegisterSingleton(schemaLoader);  
container.RegisterSingleton\<ISchemaProvider, SchemaProvider\>();  
container.RegisterServices();  
server.DependencyResolver = container

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [November 3, 2023, 5:50pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/4 "2023-11-03T17:50:23Z")

</div>

> [@fvancrae](#):
>
> very sporadically

Curious. the you say “very sporadically”, how often does this happen (one a day? week? month?), and how many requests succeed in comparison (ie is it one in 10 or one in a million)? Can you see _any_ system or commonality between the requests that fail? e.g., is it always the same client, or always the same data table, or the like?

Is the above call stack complete? ie does it not go deeper than `OffNetDataAbstractService.GetData`? (which is odd).

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 4, 2023, 9:23am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/5 "2023-11-04T09:23:50Z")

</div>

We have not witnessed the issue inhouse ourselves  
Our application is deployed on ~400 machines.  
Only one customer reported this issue twice  
I tested some other customer logs and saw other occurances  
For one customer the month october had 16 errors in another DA schema (not with schemaloader) out of 100k+ DA calls.  
I do not see any commonality. The service is typically up for days without issues. First noticed occurance ~15/10  
We catch the exception and log the callstack in our .NET code, I presume that code limits the callstack size.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [November 4, 2023, 12:25pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/6 "2023-11-04T12:25:02Z")

</div>

> [@fvancrae](#):
>
> We have not witnessed the issue inhouse ourselves  
> Our application is deployed on ~400 machines.  
> Only one customer reported this issue twice  
> I tested some other customer logs and saw other occurances  
> For one customer the month october had 16 errors in another DA schema (not with schemaloader) out of 100k+ DA calls.  
> I do not see any commonality. The service is typically up for days without issues. First noticed occurance ~15/10

Very strange. Best I can do right now is have a dry code review for this next week to see if I can find anything obviously, but on first look tis is very much a “this can never happen” scenario. Of course, those always are the most fun to debug 😉

I assume you are using latest (not that this class has changed much recently)?

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 7, 2023, 8:43am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/7 "2023-11-07T08:43:55Z")

</div>

At present we are using RO v10.0.0.15533  
I will send you the source in a private mail

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 7, 2023, 1:09pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/8 "2023-11-07T13:09:06Z")

</div>

Hi,

> [@fvancrae](#):
>
> What could cause this?

can you add `BeforeActivate` and `BeforeDeactivate` events and write to log messages like `BeforeActivate is called` & `BeforeDeactivate is called` with ClientConnectionId, pls?

it will help to detect current case:

- service wasn’t activated at all
- service was deactivated in middle of process

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 8, 2023, 7:20am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/9 "2023-11-08T07:20:13Z")

</div>

Where do I find ClientConnectionId?  
I don’t see this in the DataAbstractService or ServiceActivationEventArgs  
FYI I can log e.SessionID

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 8, 2023, 8:34am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/10 "2023-11-08T08:34:04Z")

</div>

Hi,

> [@fvancrae](#):
>
> Where do I find ClientConnectionId?  
> I don’t see this in the DataAbstractService or ServiceActivationEventArgs  
> FYI I can log e.SessionID

this is SessionID but you have logged it as ClientConnectionId 🙂

```plaintext
   bij OffNetServer.DataAbstract.OffNetDataAbstractService.GetData(String[] aTableNameArray, TableRequestInfo[] aTableRequestInfoArray)
ClientConnectionId:7f80a605-695c-4791-9c57-3a3a9b500b31

```

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 8, 2023, 8:45am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/11 "2023-11-08T08:45:12Z")

</div>

I believe the ClientConnectionId you show comes from  
sqlloggger\_.setResult(false, null, $“Exception:{ex.ToString()}”);  
Looking at the log file where this is dumped this is part of System.Data.SqlClient.SqlException.ToString() but this is not the error we are discussing.

I would like to investigate the RemObjects.SDK.Exceptions.ServiceInstanceNotActiveException error.  
I propose to add the RO SessionId to the log file for this exception, OK?

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [November 8, 2023, 8:47am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/12 "2023-11-08T08:47:46Z")

</div>

Additional question: Is ServiceActivationEventArgs.SessionId identical to DataAbstractService.SessionId?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 8, 2023, 8:54am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/13 "2023-11-08T08:54:25Z")

</div>

Hi,

> [@fvancrae](#):
>
> I propose to add the RO SessionId to the log file for this exception, OK?

agree

> [@fvancrae](#):
>
> Additional question: Is ServiceActivationEventArgs.SessionId identical to DataAbstractService.SessionId?

yes, it is identical

* * *

finally, you will have one from two cases:

- 

```plaintext
ERROR|GenericDB(GetData/)...

```

or

- 

```plaintext
BeforeActivate is called (SessionId)
BeforeDeactivate is called (SessionId)
ERROR|GenericDB(GetData/)...

```

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [October 17, 2025, 2:44pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/14 "2025-10-17T14:44:36Z")

</div>

Our customers are reporting this error more often (due to the fact that we are making more calls to the .NET based server now)

I have attached log files which contain the RO session ID mentioned above.

What can you learn from this?

Any idea what causes this issue?

[cdt230182.7z](https://talk.remobjects.com/uploads/short-url/wxAkceWvKrDfiVQtyVHFHrCHvk4.7z) (6.7 KB)

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [October 17, 2025, 3:34pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/15 "2025-10-17T15:34:19Z")

</div>

Hi,

This error is raised when service isn’t activated correctly (i.e [IActivatableService.Activate](https://docs.remotingsdk.com/API/NET/Interfaces/IActivatableService/#Activate) isn’t called)

`Activate` is usually called automatically from class factories.

for example:

```auto
    public abstract class ClassFactory : IClassFactory
    {
...
        protected void ActivateInstance(Guid clientId, IROService instance)
        {
            if (instance is IActivatableService activatableService);
            {
                try
                {
                    activatableService.Activate(clientId, this.fEnforceSessionCheck, this.fRoles);
                }
...

```

```auto
    public class StandardClassFactory : ClassFactory
    {

        public override IROService AcquireInstance(Guid clientId, bool activate = true)
        {
            IROService lInstance = this.CreateInstance();

            if (activate)
            {
                try
                {
                    this.ActivateInstance(clientId, lInstance);
    ...

```

* * *

What class factory is used for this service ?

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [October 20, 2025, 6:55am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/16 "2025-10-20T06:55:15Z")

</div>

It’s pooled

[System.ComponentModel.DesignerCategory(“Code”)]  
[RemObjects.SDK.Server.ClassFactories.PooledClassFactory(CloudEnabledDBService.initialPoolSize, RemObjects.SDK.Server.ClassFactories.PoolBehavior.CreateAdditional, true, Timeout = int.MaxValue)]  
//[RemObjects.SDK.Server.Service(Name = CloudEnabledDBService.ROServiceName, InvokerClass = typeof(CloudEnabledDBService\_Invoker), ActivatorClass = typeof(CloudEnabledDBService\_Activator))]  
[Service]  
public class CloudEnabledDBService : Officinall.BaseClasses.OffBaseDataAbstractService, /_IROServiceStatistics,_/ IDASchemaDataFetcher

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [October 20, 2025, 6:56am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/17 "2025-10-20T06:56:26Z")

</div>

Could it be that the activate fails? What could cause this? an underlying MSSQL (DB) error?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [October 20, 2025, 10:44am UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/18 "2025-10-20T10:44:50Z")

</div>

Hi,

as I see, we have no issue with PooledClassFactory.

* * *

service may not be activated if exception was raised during validation session or roles:

```auto
        public void Activate(Guid clientId, Boolean enforceSessionCheck, string[]? roles = null)
        {
            ...
            if (this.RequireSession)
            {
                if (this.SessionManager == null)
                {
                    throw new SessionNotFoundException("No SessionManager available.");
                }

                this.fSession = this.SessionManager.GetExistingSession(this.SessionID, true);

                if (this.fSession == null)
                {
                    throw new SessionNotFoundException();
                }

                if (this.Roles?.Length > 0)
                {
                    foreach (var r in Roles)
                    {
                        if (r.StartsWith("!"))
                        {
                            if (this.fSession.Roles.Contains(r.Substring(1)))
                                throw new AccessDeniedForRoleException();
                        }
                        else
                        {
                            if (!this.fSession.Roles.Contains(r))
                                throw new AccessRequiresRoleException();
                        }
                    }
                }
            }

            this.IsActive = true; //<<<<<< this line isn't reached

```

note: You can check and log above conditions in the [BeforeActivate](https://docs.remotingsdk.com/API/NET/Classes/Service/#BeforeActivate) event

---

<div class="post-metadata">

### Author: ![fvancrae](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/f/ad7895/32.png) [@fvancrae](https://talk.remobjects.com/u/fvancrae)
#### Post date: [October 20, 2025, 12:00pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/19 "2025-10-20T12:00:40Z")

</div>

What exactly should I check?

FYI: RequireSession=false for that service

 ![image](https://talk.remobjects.com/uploads/default/original/3X/6/f/6fd0b97652622693697ecf8c2e6c2307827064d0.png)

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [October 20, 2025, 12:10pm UTC](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065/20 "2025-10-20T12:10:10Z")

</div>

Do you have any custom activation code? I would suggest to assign BeforeActivate and AfterActivate event handlers, to see if one or both of them fire.

What channel are you using? Try and see if you can set breakpoints or add logging in ServerChannel.InvokeMethod.

[Next page](https://talk.remobjects.com/t/exception-this-service-instance-has-not-been-activated-yet/29065.md?page=2)
