问题
I'm currently developping a failover service for an environment using Dynamics AX and 2 mirrored SQL servers, and I have some issues getting AX to work the way I expect it to.
I have developped a service which does the following : - try to connect to the SQL servers instances - start Dynamics AX using the reachable SQL server.
To do this, I have created 2 AX configuration files (.axc), each one pointing to a SQL server.
But when I try to start the service, no mater which way I use, AX always start using the configuration that is set using the AX server configuration tool.
Here are the command I've tried to start the AX service :
sc start AOS60$01 -regConfig=Config1
net start AOS60$01 /"-regConfig=Config1"
The service always start successfully, but doesn't care about the regConfig parameter.
As anybody an idea about how to solve this issue?
Regards,
Thomas T.
回答1:
After looking for a while after a way to start the service with the -regConfig parameter, I finally gave up and developped a method which directly edit the Registry key holding the startup configuration value.
private void UpdateRegistry(string parameter)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Dynamics Server\\6.0\\01", true);
key.SetValue("Current", parameter, RegistryValueKind.String);
key.Close();
}
public void StartLocalServiceWithCLI(string serviceToStart, string parameter)
{
try
{
UpdateRegistry(parameter);
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format("/C sc start {0} ", serviceToStart);
process.StartInfo = startInfo;
process.Start();
logger.WriteInfo(string.Format("Process {0} starting, parameters [{1}]", serviceToStart, parameter));
}
catch (Exception e)
{
logger.WriteError(string.Format("Error starting process {0}, parameters [{1}]\nError details :{2}", serviceToStart, parameter, e.Message));
}
}
来源:https://stackoverflow.com/questions/26466035/dynamics-ax-2012-regconfig-does-not-work