コード例 #1
0
 /// <summary>
 /// Stops the specified SQL Server Express LocalDB instance from running.
 /// </summary>
 /// <param name="pInstanceName">The name of the LocalDB instance to stop.</param>
 /// <param name="options">One or a combination of the flag values specifying the way to stop the instance.</param>
 /// <param name="ulTimeout">
 /// The time in seconds to wait for this operation to complete. If this
 /// value is 0, this function will return immediately without waiting for the LocalDB instance to stop.
 /// </param>
 /// <returns>The HRESULT returned by the LocalDB API.</returns>
 internal int StopInstance(string pInstanceName, StopInstanceOptions options, int ulTimeout)
 {
     return(EnsureFunctionAndInvoke(
                "LocalDBStopInstance",
                ref _localDBStopInstance,
                (function) => function(pInstanceName, (int)options, ulTimeout)));
 }
コード例 #2
0
        public void NativeMethods_Methods_Return_Correct_Value_If_Sql_LocalDb_Instance_Api_Not_Installed()
        {
            // Arrange
            Helpers.InvokeInNewAppDomain(
                () =>
            {
                NativeMethods.Registry = Mock.Of <NativeMethods.IRegistry>();

                int intValue    = default(int);
                IntPtr ptrValue = default(IntPtr);
                StopInstanceOptions stopValue = default(StopInstanceOptions);
                string stringValue            = default(string);
                StringBuilder builderValue    = default(StringBuilder);

                // Act and Assert
                AssertIsNotInstalledResult(() => NativeMethods.CreateInstance(stringValue, stringValue, intValue));
                AssertIsNotInstalledResult(() => NativeMethods.DeleteInstance(stringValue, intValue));
                AssertIsNotInstalledResult(() => NativeMethods.GetInstanceInfo(stringValue, ptrValue, intValue));
                AssertIsNotInstalledResult(() => NativeMethods.GetInstanceNames(ptrValue, ref intValue));
                AssertIsNotInstalledResult(() => NativeMethods.GetLocalDbError(intValue, intValue, builderValue, ref intValue));
                AssertIsNotInstalledResult(() => NativeMethods.GetVersionInfo(stringValue, ptrValue, intValue));
                AssertIsNotInstalledResult(() => NativeMethods.GetVersions(ptrValue, ref intValue));
                AssertIsNotInstalledResult(() => NativeMethods.ShareInstance(ptrValue, stringValue, stringValue, intValue));
                AssertIsNotInstalledResult(() => NativeMethods.StartInstance(stringValue, intValue, builderValue, ref intValue));
                AssertIsNotInstalledResult(() => NativeMethods.StartTracing());
                AssertIsNotInstalledResult(() => NativeMethods.StopInstance(stringValue, stopValue, intValue));
                AssertIsNotInstalledResult(() => NativeMethods.StopTracing());
                AssertIsNotInstalledResult(() => NativeMethods.UnshareInstance(stringValue, intValue));
            });
        }
コード例 #3
0
        public void SqlLocalDbConfigurationSection_Can_Set_Properties()
        {
            // Arrange
            Helpers.InvokeInNewAppDomain(
                () =>
            {
                bool automaticallyDeleteInstanceFiles = true;
                CultureInfo language            = CultureInfo.GetCultureInfo("es-ES");
                Type loggerType                 = typeof(EmptyLogger);
                string nativeApiOverrideVersion = "11.0";
                StopInstanceOptions stopOptions = StopInstanceOptions.KillProcess | StopInstanceOptions.NoWait;
                TimeSpan stopTimeout            = TimeSpan.FromSeconds(30);

                SqlLocalDbConfigurationSection target = new SqlLocalDbConfigurationSection();

                // Act
                target.AutomaticallyDeleteInstanceFiles = automaticallyDeleteInstanceFiles;
                target.Language   = language;
                target.LoggerType = loggerType;
                target.NativeApiOverrideVersion = nativeApiOverrideVersion;
                target.StopOptions = stopOptions;
                target.StopTimeout = stopTimeout;

                // Assert
                Assert.AreEqual(automaticallyDeleteInstanceFiles, target.AutomaticallyDeleteInstanceFiles, "SqlLocalDbConfigurationSection.AutomaticallyDeleteInstanceFiles is incorrect.");
                Assert.AreEqual(language, target.Language, "SqlLocalDbConfigurationSection.Language is incorrect.");
                Assert.AreEqual(loggerType, target.LoggerType, "SqlLocalDbConfigurationSection.LoggerType is incorrect.");
                Assert.AreEqual(nativeApiOverrideVersion, target.NativeApiOverrideVersion, "SqlLocalDbConfigurationSection.NativeApiOverrideVersion is incorrect.");
                Assert.AreEqual(stopOptions, target.StopOptions, "SqlLocalDbConfigurationSection.StopOptions is incorrect.");
                Assert.AreEqual(stopTimeout, target.StopTimeout, "SqlLocalDbConfigurationSection.StopTimeout is incorrect.");
            });
        }
コード例 #4
0
        //  -------------------
        //  StopInstance method
        //  -------------------

        /// <summary>
        /// Stops the specified SQL Server Express LocalDB instance from
        /// running.
        /// </summary>
        /// <param name="instanceName">The name of the LocalDB instance to stop.
        ///     </param>
        /// <param name="options">One or a combination of the option values
        ///     specifying the way to stop the instance.</param>
        /// <param name="timeout">The time to wait for this operation to
        ///     complete. If this value is <c>0</c>, this function will return
        ///     immediately without waiting for the LocalDB instance to stop.
        ///     </param>

        public void StopInstance(string instanceName, StopInstanceOptions options, TimeSpan timeout)
        {
            // if timeout is 0, the function returns immediately with an error code
            var t  = Convert.ToUInt32(timeout.TotalSeconds);
            var hr = library.GetFunction(nameof(LocalDBStopInstance), ref localDBStopInstance)(instanceName, (uint)options, t);

            _ = ValidateHResult(hr, t == 0 ? Constants.LOCALDB_ERROR_WAIT_TIMEOUT : 0);
        }
コード例 #5
0
 /// <summary>
 /// Logs that a SQL LocalDB instance is stopping.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="instanceName">The name of the instance that is stopping.</param>
 /// <param name="timeout">The timeout used.</param>
 /// <param name="options">The stop options used.</param>
 internal static void StoppingInstance(this ILogger logger, string instanceName, TimeSpan timeout, StopInstanceOptions options)
 => _stoppingInstance(logger, instanceName, timeout, options, null);