The ServiceState property of an object of ClassType clsServer contains the execution state of the OLAP server service (MSSQLServerOLAPService). Read the property to query the status of the service. Set the property to a value to change the execution state of the service. Decision Support Objects (DSO) partially implements the service control functions of the Microsoft® Win32® API.
Long
The following values are returned when reading ServiceState.
| Value | Description | 
|---|---|
| SERVICE_CONTINUE_PENDING | The service continue is pending. | 
| SERVICE_PAUSE_PENDING | The service pause is pending. | 
| SERVICE_PAUSED | The service is paused. | 
| SERVICE_RUNNING | The service is running. | 
| SERVICE_START_PENDING | The service is starting. | 
| SERVICE_STOP_PENDING | The service is stopping. | 
| SERVICE_STOPPED | The service is not running. | 
The following values control the service when writing ServiceState.
| Value | Requested Action | 
|---|---|
| SERVICE_PAUSED | Pause the service. | 
| SERVICE_RUNNING | Start the service if stopped or paused. | 
| SERVICE_STOP | Stop the service. | 
Read/write
If a requested action cannot be completed, such as attempting to pause a service that is not running, an error appears.
This example code can be incorporated into your program to control the execution state of MSSQLServerOLAPService using DSO.
' OLAP server service control constants 
Const OLAP_SERVICE_RUNNING = &H4 
Const OLAP_SERVICE_PAUSED = &H7 
Const OLAP_SERVICE_STOP = &H1 
 
' OLAP server status and error return constants 
Const SERVICE_CONTINUE_PENDING = &H5 
Const SERVICE_PAUSE_PENDING = &H6 
Const SERVICE_PAUSED = &H7 
Const SERVICE_RUNNING = &H4 
Const SERVICE_START_PENDING = &H2 
Const SERVICE_STOP_PENDING = &H3 
Const SERVICE_STOPPED = &H1 
 
' Additional error return constants 
Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 
Const SERVICE_ACCEPT_SHUTDOWN = &H4 
Const SERVICE_ACCEPT_STOP = &H1 
Const SERVICE_ACTIVE = &H1 
Const SERVICE_CHANGE_CONFIG = &H2 
Const SERVICE_CONTROL_CONTINUE = &H3 
Const SERVICE_CONTROL_INTERROGATE = &H4 
Const SERVICE_CONTROL_PAUSE = &H2 
Const SERVICE_CONTROL_SHUTDOWN = &H5 
Const SERVICE_CONTROL_STOP = &H1 
Const SERVICE_ENUMERATE_DEPENDENTS = &H8 
Const SERVICE_INACTIVE = &H2 
Const SERVICE_INTERROGATE = &H80 
Const SERVICE_NO_CHANGE = &HFFFF 
Const SERVICE_PAUSE_CONTINUE = &H40 
Const SERVICE_QUERY_CONFIG = &H1 
Const SERVICE_QUERY_STATUS = &H4 
Const SERVICE_STATE_ALL = (SERVICE_ACTIVE Or SERVICE_INACTIVE) 
Const SERVICE_USER_DEFINED_CONTROL = &H100 
 
Const SERVICE_WAIT_MAX_SECONDS As Integer = 30 
' ============================================================== 
' OlapServiceControl function 
' Returns True or False 
' Calling parameters: 
'     - objServer is an object of ClassType clsServer 
'     that has been created and initialized 
'     - iCmdReq is one of the OLAP server service
'      control constants
'     - lngStatus receives the status (one of the OLAP
'      server status constants) 
'     - lngErr receives status if function fails (one of the OLAP
'      server status constants or one of the additional error constants) 
 
Friend Function OlapServiceControl(objServer As Object, _ 
                                  ByVal iCmdReq As Integer, _ 
                                  ByRef lngStatus As Long, _ 
                                  ByRef lngErr As Long) As Boolean 
Dim bRet             As Boolean 
Dim lngSrvStat       As Long 
Dim iCount           As Integer 
Dim lngControlCmd    As Long 
 
lngSrvStat = myServer.ServiceState 
bRet = False 
lngControlCmd = iCmdReq 
lngErr = 0 
 
Select Case iCmdReq 
   Case SERVICE_RUNNING    ' Caller wants to start the server 
      Select Case lngSrvStat 
         Case SERVICE_RUNNING 
            bRet = True 
         Case SERVICE_PAUSED, SERVICE_STOPPED 
            objServer.ServiceState = lngControlCmd 
            For iCount = 1 To SERVICE_WAIT_MAX_SECONDS 
               lngSrvStat = objServer.ServiceState 
               If lngSrvStat = SERVICE_RUNNING Then 
                  bRet = True 
                  Exit For 
               End If 
               Call WaitNSeconds(1) 
            Next iCount 
      End Select 
 
   Case SERVICE_PAUSED    ' Caller wants to pause the server 
      Select Case lngSrvStat
         Case SERVICE_PAUSED 
            bRet = True 
         Case SERVICE_RUNNING 
            objServer.ServiceState = lngControlCmd 
            For iCount = 1 To SERVICE_WAIT_MAX_SECONDS 
               lngSrvStat = objServer.ServiceState 
               If lngSrvStat = SERVICE_PAUSED Then 
                  bRet = True 
                  Exit For 
               End If 
               Call WaitNSeconds(1) 
            Next iCount 
         Case SERVICE_STOPPED 
            bRet = False 
      End Select 
 
   Case SERVICE_STOP     ' Caller wants to stop the server 
      Select Case lngSrvStat
         Case SERVICE_STOPPED 
            bRet = True 
         Case SERVICE_PAUSED 
            bRet = False 
         Case SERVICE_RUNNING 
            objServer.ServiceState = lngControlCmd 
            For iCount = 1 To SERVICE_WAIT_MAX_SECONDS 
               lngSrvStat = objServer.ServiceState 
               If lngSrvStat = SERVICE_STOPPED Then 
                  bRet = True 
                  Exit For 
               End If 
               Call WaitNSeconds(1) 
            Next iCount 
      End Select 
End Select 
 
lngStatus = lngSrvStat
If Not bRet Then 
   lngErr = lngSS 
End If 
OlapServiceControl = bRet 
 
End Function 
' ============================================================== 
Private Sub WaitNSeconds(iSeconds As Integer) 
Dim dteFinish      As Date 
dteFinish = DateAdd("s", iSeconds, Now) 
Do While Now < dteFinish 
   DoEvents    ' Yield to other processes. 
Loop 
End Sub