我正在創建一個windows服務,它假定在特定表中查找數據,然後根據狀態處理記錄。在安裝過程中將參數傳遞給Windows服務
我想在使用installutill作爲參數安裝服務並將它們保存在註冊表內時傳遞數據庫憑據。我已經嘗試使用代碼波紋管,但是我一直在事件「OnBeforeInstall」上發生錯誤。
我相信要麼我錯誤地傳遞參數,要麼我在錯誤的事件中編寫代碼。需要你的幫助來確定我做錯了什麼。
protected override void OnBeforeInstall(IDictionary savedState)
{
base.OnBeforeInstall(savedState);
_eventLog.WriteEntry("OnBeforeInstall Started");
try
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\RyteRMS");
if (key != null)
{
_eventLog.WriteEntry("Write data to registry key");
key.SetValue("DBTYPE", this.Context.Parameters["dbtype"].ToString()); // This throws error, I am assuming as the above event entry is visible.
key.SetValue("DATASOURCE", this.Context.Parameters["datasource"].ToString());
key.SetValue("USERID", this.Context.Parameters["userid"].ToString());
key.SetValue("PASSWORD", this.Context.Parameters["password"].ToString());
key.SetValue("DBNAME", this.Context.Parameters["dbname"].ToString());
key.Close();
}
}
catch (Exception ex)
{
_eventLog.WriteEntry(ex.Message);
}
_eventLog.WriteEntry("OnBeforeInstall Finished");
}
我在命令提示寫這: installutil RMSBGService.exe/DBTYPE = SQLSERVER /數據源= hitin-LT/DBNAME = RMS /用戶ID =管理員/密碼= PASSW0RD
錯誤:「未將對象引用設置爲對象的實例。」
P.S.我不知道如何調試Win服務,所以我使用事件日誌來記錄每一件事情。