//判斷SQL Server是否已經啟動,如果沒有啟動則做相應處理
st_status.text='判斷SQL Server是否已經啟動 ...'
OLEObject PBObject
long ll_status
PBObject = CREATE OLEObject
ll_status = PBObject.ConnectToNewObject ("SQLDMO.sqlserver")
string ls_serverName
integer li_Return
string ls_UserName
String ls_PassWord
Constant Integer SQLDMOSvc_Unknown =0//未知狀態
Constant Integer SQLDMOSvc_Running =1//已經啟動
Constant Integer SQLDMOSvc_Paused =2//SQL Server為暫停狀態
Constant Integer SQLDMOSvc_Stopped =3//SQL Server為停止狀態
Constant Integer SQLDMOSvc_Starting =4//SQLSERVER正在啟動(關閉啟動)
Constant Integer SQLDMOSvc_Stopping =5//SQLSERVER正在關閉
Constant integer SQLDMOSvc_Continuing=6//SQLSERVER正在啟動(暫停啟動)
Constant Integer SQLDMOSvc_Pausing =7//SQLSERVER正在暫停(啟動暫停)
ls_ServerName='218.71.42.229'
ls_UserName='sa'
ls_passWord=''
IF ll_status = 0 THEN //連接成功
PBObject.name = ls_servername
PBObject.logintimeout=10
PBObject.LoginSecure = True //以NT方式連接
//PBObject.LoginSecure = false //以SQL Server方式連接
IF isNull(PBObject) Then Return
Try
li_return = PBObject.Status
Catch(RunTimeError rte)
Messagebox("提示","沒有安裝SQLServer",StopSign!)
End try
Choose case li_return
case 1 //已經啟動
st_Status.text=ls_ServerName+'已經啟動SQLSERVER服務器'
//PBObject.stop()//停止SQLSERVER
case 2 //SQL Server為暫停狀態
st_status.text = '啟動' + ls_servername + '上的SQL Server ...(暫停啟動)'
PBObject.Continue()
case 3 //SQL Server為停止狀態
st_status.text = '啟動'+ ls_servername + '上的SQL Server ...(停止啟動)'
PBObject.Start(false,ls_servername,ls_username,ls_passWord)//啟動SQL Server
case 4 //SQLSERVER正在啟動(關閉啟動)
st_status.text = ls_servername + '上的SQL Server 正在啟動(關閉啟動)'
PBObject.start(false,'sa','')//停止SQLSERVER
case 5 //SQLSERVER正在關閉
st_status.text = ls_servername + '上的SQL Server 正在關閉'
case 6 //SQLSERVER正在啟動(暫停啟動)
st_status.text = ls_servername + '上的SQL Server 正在啟動(暫停啟動)'
case 7 //SQLSERVER正在暫停(啟動暫停)
st_status.text = ls_servername + '上的SQL Server 正在暫停'
case 0 //未知狀態
st_