/// <summary> /// Sets instance specific parameters after an Ese instance has been created. /// </summary> /// <param name="instance">The instance handle to use.</param> public void SetInstanceParams(JET_INSTANCE instance) { Action <DatabaseConfig, JET_INSTANCE, int> setParamIfExists = (engineConfig, inst, param) => { object value; if (engineConfig.ParamStore.TryGetValue(param, out value)) { DatabaseConfig.SetParamOnInstance(inst, param, value); } }; // First, set parameters that require to be set in a particular order #if !ESENT && !MANAGEDESENT_ON_WSA setParamIfExists(this, instance, (int)Windows10Param.ConfigStoreSpec); #endif setParamIfExists(this, instance, (int)VistaParam.EnableAdvanced); setParamIfExists(this, instance, (int)VistaParam.Configuration); for (int i = 0; i < DatabaseConfig.ParamTable.Length; i++) { if (!DatabaseConfig.ParamTable[i].StaticAfterGlobalInit #if !ESENT && !MANAGEDESENT_ON_WSA && i != (int)Windows10Param.ConfigStoreSpec #endif && i != (int)VistaParam.EnableAdvanced && i != (int)VistaParam.Configuration) { setParamIfExists(this, instance, i); } } }
/// <summary> /// Sets global parameters before an Ese instance is created. /// </summary> public void SetGlobalParams() { // Lock this section using a process-wide lock, so in case of a race between two threads, a config set is either completely set or completely over-written DatabaseConfig.GlobalParamsMutex.WaitOne(); try { for (int i = 0; i < DatabaseConfig.ParamTable.Length; i++) { // This check ensures that only global params that must be set before global init are set here // This protects instance params from being set before instance init. Setting them here would change the defaults for these params // for all future instances. That would be really bad because the settings contained in the current config set would 'spill over' // into future config sets. if (DatabaseConfig.ParamTable[i].StaticAfterGlobalInit) { object valueToSet; if (this.ParamStore.TryGetValue(i, out valueToSet)) { object currValue; DatabaseConfig.TryGetParamFromInstance(JET_INSTANCE.Nil, i, out currValue); if (!currValue.Equals(valueToSet)) { DatabaseConfig.SetParamOnInstance(JET_INSTANCE.Nil, i, valueToSet); } } } } } finally { DatabaseConfig.GlobalParamsMutex.ReleaseMutex(); } }