예제 #1
0
        public SmoResult DetachDatabaseSql(string xiSqlInstanceName, string xiUserId, string xiPassword)
        {
            Assert.NonEmptyString(xiSqlInstanceName, "xiSqlInstanceName");

            m_Timer.Enabled = false;

            CurrentInstance.Name = string.Empty;

            SmoResult result = new SmoResult();

            result.DatabaseName = AttachedDatabaseName;
            result.Success      = true;
            result.Message      = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(AttachedDatabaseName))
                {
                    Smo.DetachDatabase(xiSqlInstanceName, SmoAuthenticationMode.SqlServerAuthentication, xiUserId, xiPassword, AttachedDatabaseName);
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = Logger.CollectExceptionMessages(ex);
            }

            return(result);
        }
예제 #2
0
        public SmoResult AttachDatabaseSql(string xiSqlInstanceName, string xiUserId, string xiPassword, IList <string> xiDatabaseFiles)
        {
            Assert.NonEmptyString(xiSqlInstanceName, "xiSqlInstanceName");

            AttachedDatabaseName = Smo.GetDatabaseName(Smo.GetPrefixFromDbFiles(xiDatabaseFiles), xiSqlInstanceName, SmoAuthenticationMode.WindowsAuthentication, xiUserId, xiPassword);

            CurrentInstance.Name = string.Empty;

            SmoResult result = new SmoResult();

            result.DatabaseName = AttachedDatabaseName;
            result.Success      = true;
            result.Message      = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(AttachedDatabaseName))
                {
                    Smo.AttachDatabase(xiSqlInstanceName, SmoAuthenticationMode.SqlServerAuthentication, xiUserId, xiPassword, AttachedDatabaseName, xiDatabaseFiles);

                    CurrentInstance.Name               = AttachedDatabaseName;
                    CurrentInstance.Server             = xiSqlInstanceName;
                    CurrentInstance.Instance           = xiSqlInstanceName;
                    CurrentInstance.IsClustered        = false;
                    CurrentInstance.Version            = string.Empty;
                    CurrentInstance.IsLocal            = false;
                    CurrentInstance.IsDefault          = false;
                    CurrentInstance.ConnectionString   = string.Empty;
                    CurrentInstance.UserName           = xiUserId;
                    CurrentInstance.Password           = xiPassword;
                    CurrentInstance.AuthenticationMode = SmoAuthenticationMode.SqlServerAuthentication;

                    PingDatabase();
                    PingRemoteFolder();

                    m_Timer.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                m_Timer.Enabled = false;

                result.Success = false;
                result.Message = Logger.CollectExceptionMessages(ex);
            }

            return(result);
        }