Partilhar via


ServiceState (clsServer)

ObservaçãoObservação

  Esse recurso será removido na próxima versão do Microsoft SQL Server. Não utilize esse recurso em desenvolvimentos novos e modifique, assim que possível, os aplicativos que atualmente o utilizam.

The ServiceState property of an object of ClassType clsServer contains the execution state of the Analysis server service (MSSQLServerOLAPService).

Data Type

Long

Values

The values of this property are different depending on whether the property is being read or set.

The following values are returned when reading this property.

Value

Description

SERVICE_CONTINUE_PENDING

A previous request to continue a paused service is pending.

SERVICE_PAUSE_PENDING

A previous request to pause a running service 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 table describes the values used to control the Analysis server.

Value

Requested action

SERVICE_PAUSED

Pause the service.

SERVICE_RUNNING

Start the service if stopped or paused.

SERVICE_STOP

Stop the service.

Access

Read/write

Comentários

Read the property to query the status of the service. To change the execution state of the service, set the property to a value. Decision Support Objects (DSO) partially implements the service control functions of the Microsoft® Win32® API.

If a requested action cannot be completed, such as attempting to pause a service that is not running, or the request times out (within 60 seconds), an error occurs.

Exemplo

Use the following code to set the execution state of MSSQLServerOLAPService:

' Analysis server service control constants 
Const OLAP_SERVICE_RUNNING = &H4 
Const OLAP_SERVICE_PAUSED = &H7 
Const OLAP_SERVICE_STOP = &H1 
 
' Analysis 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 Analysis server service
'     control constants
'    - lngStatus receives the status (one of the Analysis
'     server status constants) 
'    - lngErr receives status if function fails (one of the Analysis
'     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 lngControlCmd    As Long 

lngSrvStat = objServer.ServiceState 
bRet = False 
lngControlCmd = iCmdReq 
lngErr = 0 

On Error GoTo Err_State

Select Case iCmdReq 
   ' Caller wants to start the server    
   Case SERVICE_RUNNING    
      ' Check the current server status 
      Select Case lngSrvStat 
         ' If it is already running, return True
         Case SERVICE_RUNNING 
            bRet = True 
         Case SERVICE_PAUSED, SERVICE_STOPPED 
            objServer.ServiceState = lngControlCmd 
            bRet = True 
      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 
            bRet = True 
         ' Trying to pause a stopped service 
         ' raises an error from the Server object.
         Case SERVICE_STOPPED 
            bRet = False 
      End Select 

   Case SERVICE_STOPPED     ' Caller wants to stop the server 
      Select Case lngSrvStat
         Case SERVICE_STOPPED 
            bRet = True 
         Case SERVICE_RUNNING
            objServer.ServiceState = lngControlCmd 
            bRet = True 
         ' Trying to stop a paused service 
         ' raises an error from the Server object.
         Case SERVICE_PAUSED
            bRet = False
      End Select 
End Select 

' Put the current state of the service into lngStatus
lngStatus = objServer.ServiceState

OlapServiceControl = bRet 

Exit Function

Err_State:
' Catch the error returned by the server object
' Some reasons that can cause an error:
'  Server object unable to contact service control
'  manager or Analysis service application
'  Service does not respond to state change 
'  request within 60 seconds
'  An invalid request is sent to the service (for example,
'  trying to pause a stopped service)

lngStatus = objServer.ServiceState
lngErr = Err.Number
OlapServiceControl = False

End Function 

Consulte também

Referência