static internal OperationAbortedException Aborted(Exception inner) { OperationAbortedException e; if (inner == null) { e = new OperationAbortedException(StringsHelper.GetString(Strings.ADP_OperationAborted), null); } else { e = new OperationAbortedException(StringsHelper.GetString(Strings.ADP_OperationAbortedExceptionMessage), inner); } ADP.TraceExceptionAsReturnValue(e); return(e); }
const int const_ErrorMessageBufferSize = 1024; // Buffer size for Local DB error message, according to Serverless team, 1K will be enough for all messages internal static string GetLocalDBMessage(int hrCode) { Debug.Assert(hrCode < 0, "HRCode does not indicate error"); try { StringBuilder buffer = new StringBuilder((int)const_ErrorMessageBufferSize); UInt32 len = (UInt32)buffer.Capacity; // First try for current culture int hResult = LocalDBFormatMessage(hrLocalDB: hrCode, dwFlags: const_LOCALDB_TRUNCATE_ERR_MESSAGE, dwLanguageId: (UInt32)CultureInfo.CurrentCulture.LCID, buffer: buffer, buflen: ref len); if (hResult >= 0) { return(buffer.ToString()); } else { // Message is not available for current culture, try default buffer = new StringBuilder((int)const_ErrorMessageBufferSize); len = (UInt32)buffer.Capacity; hResult = LocalDBFormatMessage(hrLocalDB: hrCode, dwFlags: const_LOCALDB_TRUNCATE_ERR_MESSAGE, dwLanguageId: 0 /* thread locale with fallback to English */, buffer: buffer, buflen: ref len); if (hResult >= 0) { return(buffer.ToString()); } else { return(string.Format(CultureInfo.CurrentCulture, "{0} (0x{1:X}).", StringsHelper.GetString("LocalDB_UnobtainableMessage"), hResult)); } } } catch (SqlException exc) { return(string.Format(CultureInfo.CurrentCulture, "{0} ({1}).", StringsHelper.GetString("LocalDB_UnobtainableMessage"), exc.Message)); } }
internal static void CreateLocalDBInstance(string instance) { DemandLocalDBPermissions(); if (s_configurableInstances == null) { // load list of instances from configuration, mark them as not created bool lockTaken = false; RuntimeHelpers.PrepareConstrainedRegions(); try { Monitor.Enter(s_configLock, ref lockTaken); if (s_configurableInstances == null) { Dictionary <string, InstanceInfo> tempConfigurableInstances = new Dictionary <string, InstanceInfo>(StringComparer.OrdinalIgnoreCase); object section = PrivilegedConfigurationManager.GetSection("system.data.localdb"); if (section != null) // if no section just skip creation { // validate section type LocalDBConfigurationSection configSection = section as LocalDBConfigurationSection; if (configSection == null) { throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_BadConfigSectionType")); } foreach (LocalDBInstanceElement confElement in configSection.LocalDbInstances) { Debug.Assert(confElement.Name != null && confElement.Version != null, "Both name and version should not be null"); tempConfigurableInstances.Add(confElement.Name.Trim(), new InstanceInfo(confElement.Version.Trim())); } } else { SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> No system.data.localdb section found in configuration"); } s_configurableInstances = tempConfigurableInstances; } } finally { if (lockTaken) { Monitor.Exit(s_configLock); } } } InstanceInfo instanceInfo = null; if (!s_configurableInstances.TryGetValue(instance, out instanceInfo)) { return; // instance name was not in the config } if (instanceInfo.created) { return; // instance has already been created } Debug.Assert(!instance.Contains("\0"), "Instance name should contain embedded nulls"); if (instanceInfo.version.Contains("\0")) { throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_InvalidVersion"), instance: instance); } // LocalDBCreateInstance is thread- and cross-process safe method, it is OK to call from two threads simultaneously int hr = LocalDBCreateInstance(instanceInfo.version, instance, flags: 0); SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> Starting creation of instance {0} version {1}", instance, instanceInfo.version); if (hr < 0) { throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_CreateFailed"), instance: instance, localDbError: hr); } SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> Finished creation of instance {0}", instance); instanceInfo.created = true; // mark instance as created } // CreateLocalDbInstance
public static Exception InvalidOffsetLength() { return(_Argument(StringsHelper.GetString(Strings.Data_InvalidOffsetLength))); }
protected override string GetLocalizedString(string value) { return(StringsHelper.GetString(value)); }