你設定服務的依賴項,指明該服務依賴MSSQL,就應該能自動啟動成功了。
例:
服務專案裡的Installer類里加入System.ServiceProcess.ServiceInstaller元件和ServiceProcessInstaller元件,
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
然後寫InitializeComponent()方法
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
this.serviceInstaller1.ServiceName = "YourServiceName";
this.serviceInstaller1.ServicesDependedOn = new string[] {"MSSQLSERVER"};
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.serviceProcessInstaller1, this.serviceInstaller1});
}
你設定服務的依賴項,指明該服務依賴MSSQL,就應該能自動啟動成功了。
例:
服務專案裡的Installer類里加入System.ServiceProcess.ServiceInstaller元件和ServiceProcessInstaller元件,
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
然後寫InitializeComponent()方法
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
this.serviceInstaller1.ServiceName = "YourServiceName";
this.serviceInstaller1.ServicesDependedOn = new string[] {"MSSQLSERVER"};
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.serviceProcessInstaller1, this.serviceInstaller1});
}