Home > Net >  How do I get used to the service name
How do I get used to the service name

Time:03-25

Your computer to install the SQL is not the 2000 version, want to design a mimic SQL2000 service manager of desktop applications, there are two problems,
1, do not know how to get in the service name,
2, stop service will be the exception, error for the System. InvalidOperationException: "unable to open the computer". "on the MSSQL $SQLEXPRESS, should be how to modify,



The program code is as follows:
 
Private int Number, StateIndex;
Private readonly ServiceController Sc;

Public frmSqlManage ()
{
InitializeComponent ();
Number=0;
Sc=new ServiceController (MSSQLSERVER "");//different computer service name is not the same, not all call MSSQLSERVER,
}

 
Private void btnStop_Click (object sender, EventArgs e)
{
Sc. Stop ();//it will be the exception, System. InvalidOperationException: "unable to open the computer". "on the MSSQL $SQLEXPRESS, should how to change?
Sc. Refresh ();
Get_SqlState ();
Set_nfiInfo_Icon_Text ();
}

CodePudding user response:

When the SQL service stops, click start the service, will also appear abnormal, strange, the same code on this computer no exception, in another computer is abnormal,
This is the exception information, whether the SQL version problem, no exception is SQL2000, the exception is SQL2019, does that matter?



This is related to the program code
 
Private void btnRun_Click (object sender, EventArgs e)
{
If (StateIndex==1)//state Numbers for 1 service has stopped
{
Sc. Start ();//is it out of the abnormal, how to change?
}
The else
{
Sc. Continue ();
}
Sc. Refresh ();
Get_SqlState ();
Set_nfiInfo_Icon_Text ();
}
  •  Tags:  
  • C#
  • Related