I am creating a windows service which is suppose to look up data in a specific table and then process the record based the status.
I want to pass the DB credentials while I install the service using installutill as parameters and save them inside registry. I have tried doing so using the code bellow, but I keep getting error on the event "OnBeforeInstall".
I believe either I am passing the parameters incorrectly or I am writing code in the wrong event. Need your help to figure what am I doing wrong.
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");
}
I am writing this on the command prompt: installutil RMSBGService.exe /dbtype=sqlserver /datasource=hitin-lt /dbname=rms /userid=admin /password=passw0rd
Error: "Object reference not set to an instance of an object."
P.S. I dont know how to debug the Win Service, so I am using event log to record every thing.