Ejemplo n.º 1
0
        /// <summary>
        /// Shares the specified SQL Server LocalDB instance with other users of the computer,
        /// using the specified shared name for the current Windows user.
        /// </summary>
        /// <param name="api">The <see cref="ISqlLocalDbApi"/> to use to share the instance.</param>
        /// <param name="instanceName">The private name for the LocalDB instance to share.</param>
        /// <param name="sharedInstanceName">The shared name for the LocalDB instance to share.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="api"/>, <paramref name="instanceName"/> or <paramref name="sharedInstanceName"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="PlatformNotSupportedException">
        /// The method is called from a non-Windows operating system.
        /// </exception>
        public static void ShareInstance(this ISqlLocalDbApi api, string instanceName, string sharedInstanceName)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            SqlLocalDbApi.EnsurePlatformSupported();

            string ownerSid;

            using (var identity = WindowsIdentity.GetCurrent())
            {
                ownerSid = identity.User.Value;
            }

            api.ShareInstance(ownerSid, instanceName, sharedInstanceName);
        }