コード例 #1
0
        public void System_Data_SqlLocalDb_Assembly_Can_Be_Used_End_To_End_To_Trace_Create_And_Share_Instances()
        {
            Helpers.EnsureUserIsAdmin();

            SqlLocalDbApiWrapper target = new SqlLocalDbApiWrapper();

            if (!target.IsLocalDBInstalled())
            {
                Assert.Fail("SQL LocalDB is not installed.");
            }

            string instanceName = Guid.NewGuid().ToString();
            string version      = target.LatestVersion;

            target.StartTracing();

            try
            {
                target.CreateInstance(instanceName, version);

                try
                {
                    target.StartInstance(instanceName);

                    try
                    {
                        string ownerSid;

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

                        string sharedInstanceName = Guid.NewGuid().ToString();

                        target.ShareInstance(ownerSid, instanceName, sharedInstanceName);
                        target.UnshareInstance(instanceName);
                    }
                    finally
                    {
                        target.StopInstance(instanceName, SqlLocalDbApi.StopTimeout);
                    }
                }
                finally
                {
                    target.DeleteInstance(instanceName);
                }
            }
            finally
            {
                target.StopTracing();
            }
        }
        private bool disposedValue = false; // To detect redundant calls

        protected void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    // Optional. 
                    // By default, the next test class which uses TestignSiloHost will
                    // cause a fresh Orleans silo environment to be created.
                    this.HostedCluster.StopAllSilos();

                    instance.Stop();
                    ISqlLocalDbApi localDB = new SqlLocalDbApiWrapper();
                    localDB.DeleteInstance(instance.Name);

                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
コード例 #3
0
        internal static void Main(string[] args)
        {
            PrintBanner();

            ISqlLocalDbApi localDB = new SqlLocalDbApiWrapper();

            if (!localDB.IsLocalDBInstalled())
            {
                Console.WriteLine(SR.SqlLocalDbApi_NotInstalledFormat, Environment.MachineName);
                return;
            }

            if (args != null &&
                args.Length == 1 &&
                string.Equals(args[0], "/deleteuserinstances", StringComparison.OrdinalIgnoreCase))
            {
                SqlLocalDbApi.DeleteUserInstances(deleteFiles: true);
            }

            ISqlLocalDbProvider provider = new SqlLocalDbProvider();

            IList<ISqlLocalDbVersionInfo> versions = provider.GetVersions();

            Console.WriteLine(Strings.Program_VersionsListHeader);
            Console.WriteLine();

            foreach (ISqlLocalDbVersionInfo version in versions)
            {
                Console.WriteLine(version.Name);
            }

            Console.WriteLine();

            IList<ISqlLocalDbInstanceInfo> instances = provider.GetInstances();

            Console.WriteLine(Strings.Program_InstancesListHeader);
            Console.WriteLine();

            foreach (ISqlLocalDbInstanceInfo instanceInfo in instances)
            {
                Console.WriteLine(instanceInfo.Name);
            }

            Console.WriteLine();

            string instanceName = Guid.NewGuid().ToString();

            ISqlLocalDbInstance instance = provider.CreateInstance(instanceName);

            instance.Start();

            try
            {
                if (IsCurrentUserAdmin())
                {
                    instance.Share(Guid.NewGuid().ToString());
                }

                try
                {
                    using (SqlConnection connection = instance.CreateConnection())
                    {
                        connection.Open();

                        try
                        {
                            using (SqlCommand command = new SqlCommand("create database [MyDatabase]", connection))
                            {
                                command.ExecuteNonQuery();
                            }

                            using (SqlCommand command = new SqlCommand("drop database [MyDatabase]", connection))
                            {
                                command.ExecuteNonQuery();
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
                finally
                {
                    if (IsCurrentUserAdmin())
                    {
                        instance.Unshare();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                instance.Stop();
                localDB.DeleteInstance(instance.Name);
            }

            Console.WriteLine();
            Console.Write(Strings.Program_ExitPrompt);
            Console.ReadKey();
        }
コード例 #4
0
        public void System_Data_SqlLocalDb_Assembly_Can_Be_Used_End_To_End_To_Trace_Create_And_Share_Instances()
        {
            Helpers.EnsureUserIsAdmin();

            SqlLocalDbApiWrapper target = new SqlLocalDbApiWrapper();

            if (!target.IsLocalDBInstalled())
            {
                Assert.Fail("SQL LocalDB is not installed.");
            }

            string instanceName = Guid.NewGuid().ToString();
            string version = target.LatestVersion;

            target.StartTracing();

            try
            {
                target.CreateInstance(instanceName, version);

                try
                {
                    target.StartInstance(instanceName);

                    try
                    {
                        string ownerSid;

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

                        string sharedInstanceName = Guid.NewGuid().ToString();

                        target.ShareInstance(ownerSid, instanceName, sharedInstanceName);
                        target.UnshareInstance(instanceName);
                    }
                    finally
                    {
                        target.StopInstance(instanceName, SqlLocalDbApi.StopTimeout);
                    }
                }
                finally
                {
                    target.DeleteInstance(instanceName);
                }
            }
            finally
            {
                target.StopTracing();
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: vinamraarya/sqllocaldb
        internal static void Main(string[] args)
        {
            PrintBanner();

            ISqlLocalDbApi localDB = new SqlLocalDbApiWrapper();

            if (!localDB.IsLocalDBInstalled())
            {
                Console.WriteLine(SR.SqlLocalDbApi_NotInstalledFormat, Environment.MachineName);
                return;
            }

            if (args?.Length == 1 && string.Equals(args[0], "/deleteuserinstances", StringComparison.OrdinalIgnoreCase))
            {
                SqlLocalDbApi.DeleteUserInstances(deleteFiles: true);
            }

            ISqlLocalDbProvider provider = new SqlLocalDbProvider();

            IList <ISqlLocalDbVersionInfo> versions = provider.GetVersions();

            Console.WriteLine(Strings.Program_VersionsListHeader);
            Console.WriteLine();

            foreach (ISqlLocalDbVersionInfo version in versions)
            {
                Console.WriteLine(version.Name);
            }

            Console.WriteLine();

            IList <ISqlLocalDbInstanceInfo> instances = provider.GetInstances();

            Console.WriteLine(Strings.Program_InstancesListHeader);
            Console.WriteLine();

            foreach (ISqlLocalDbInstanceInfo instanceInfo in instances)
            {
                Console.WriteLine(instanceInfo.Name);
            }

            Console.WriteLine();

            string instanceName = Guid.NewGuid().ToString();

            ISqlLocalDbInstance instance = provider.CreateInstance(instanceName);

            instance.Start();

            try
            {
                if (IsCurrentUserAdmin())
                {
                    instance.Share(Guid.NewGuid().ToString());
                }

                try
                {
                    using (SqlConnection connection = instance.CreateConnection())
                    {
                        connection.Open();

                        try
                        {
                            using (SqlCommand command = new SqlCommand("create database [MyDatabase]", connection))
                            {
                                command.ExecuteNonQuery();
                            }

                            using (SqlCommand command = new SqlCommand("drop database [MyDatabase]", connection))
                            {
                                command.ExecuteNonQuery();
                            }
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
                finally
                {
                    if (IsCurrentUserAdmin())
                    {
                        instance.Unshare();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                instance.Stop();
                localDB.DeleteInstance(instance.Name);
            }

            Console.WriteLine();
            Console.Write(Strings.Program_ExitPrompt);
            Console.ReadKey();
        }