all groups > sql server msde > march 2006 >
You're in the

sql server msde

group:

Restarting the Server


Restarting the Server Marcos Lommez
3/21/2006 11:48:47 AM
sql server msde:
How can i restart my MSDE server from another application? Is there any api
to this?

Thanks

Re: Restarting the Server Andrea Montanari
3/21/2006 6:13:18 PM
hi Marcos,
[quoted text, click to view]

you can perhaps use SQL-DMO object model, using the SQLDMOSqlServer object
and it's methods .ShutDown and .Start, according to enought permission of
the current login, but I do think including that dependency is overkill for
that requirement..
you can locally use NET STOP/START commands from the OS shell,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_1_start_7kdn.asp,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_1_start_5qih.asp,
again, depending on account permissions...
where come these requirements for?
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.18.0 - DbaMgr ver 0.62.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

Re: Restarting the Server Marcos Lommez
3/21/2006 6:16:24 PM
I need this because after installing the MSDE through InstallShield, im
changing the listening port in the windows registry. So i need to restart
it.

Im not an advanced of MS SQL Server. What would be SQL-DMO?
Is possible to implement that object in Delphi language for example?

Thanks again Andrea


"Andrea Montanari" <andrea.sqlDMO@virgilio.it> escreveu na mensagem
news:48aqhdFjdnj3U1@individual.net...
[quoted text, click to view]

Re: Restarting the Server Andrea Montanari
3/22/2006 12:00:00 AM
hi Marcos,
[quoted text, click to view]

SQL-DMO is a COM component and you can use it in Delphi.., but it must be
registered at install time (actually you are the installer) and I really do
not know if it works in this condition...
but you can have a look at the scm, SQL Service Control Manager API,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/coprompt/cp_scm_9f95.asp
c:\..\>scm.exe -Action 1 -Silent 1 -Service MSSQL$InstanceName

or even something like (VB6)
Option Explicit

Private Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type

Private Const SERVICE_STOP = &H20
Private Const SERVICE_CONTROL_STOP = &H1
Private Const SC_MANAGER_CONNECT = &H1
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

Private Declare Function OpenSCManager Lib "advapi32.dll" Alias
"OpenSCManagerA" _
(ByVal lpMachineName As String, _
ByVal lpDatabaseName As String, _
ByVal dwDesiredAccess As Long) As Long

Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA"
_
(ByVal hSCManager As Long, _
ByVal lpServiceName As String, _
ByVal dwDesiredAccess As Long) As Long

Private Declare Function ControlService Lib "advapi32.dll" _
(ByVal hService As Long, _
ByVal dwControl As Long, _
lpServiceStatus As SERVICE_STATUS) As Long

Private Declare Function CloseServiceHandle Lib "advapi32.dll" _
(ByVal hSCObject As Long) As Long

Private Declare Function GetLastError Lib "kernel32" () As Long

Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA"
_
(ByVal dwFlags As Long, _
lpSource As Any, _
ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, _
ByVal lpBuffer As String, _
ByVal nSize As Long, _
Arguments As Long) As Long

Private Sub ErrorMessage()
Dim ErrCode As Long
Dim NumCar As Long
Dim Text As String

ErrCode = GetLastError
Text = Space$(1000)
NumCar = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrCode, 0, Text,
Len(Text), 0)
MsgBox Text, vbCritical
End Sub

Public Sub StopService(ByVal ServiceName As String)
Dim hSCManager As Long
Dim hService As Long
Dim hControl As Long
Dim hClose As Long
Dim ServStatus As SERVICE_STATUS

'open services database
hSCManager = OpenSCManager(vbNullString, vbNullString,
SC_MANAGER_CONNECT)
If hSCManager <> 0 Then
'access the service
hService = OpenService(hSCManager, ServiceName, SERVICE_STOP)
If hService <> 0 Then
'post "Stop" command to it
hControl = ControlService(hService, SERVICE_CONTROL_STOP,
ServStatus)
If hControl <> 0 Then
'clean-up and close handlers
hClose = CloseServiceHandle(hService)
Else
ErrorMessage
End If
Else
ErrorMessage
End If
hClose = CloseServiceHandle(hSCManager)
Else
ErrorMessage
End If
End Sub

Sub Main()
StopService "MSSQLServer"
End Sub

--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.18.0 - DbaMgr ver 0.62.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

AddThis Social Bookmark Button