///--------------------------------------------------------------------------------
        /// <summary>This method determines whether or not any metadata is
        /// different between the input instance and the current instance.</summary>
        ///
        /// <param name="inputDatabaseSource">The databasesource to compare metadata.</param>
        ///--------------------------------------------------------------------------------
        public bool IsIdenticalMetadata(DatabaseSource inputDatabaseSource)
        {
            if (SourceDbServerName.GetString() != inputDatabaseSource.SourceDbServerName.GetString())
            {
                return(false);
            }
            if (SourceDbName.GetString() != inputDatabaseSource.SourceDbName.GetString())
            {
                return(false);
            }
            if (DatabaseTypeCode.GetInt() != inputDatabaseSource.DatabaseTypeCode.GetInt())
            {
                return(false);
            }
            if (UserName.GetString() != inputDatabaseSource.UserName.GetString())
            {
                return(false);
            }
            if (Password.GetString() != inputDatabaseSource.Password.GetString())
            {
                return(false);
            }

            #region protected
            #endregion protected

            return(true);
        }
예제 #2
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method loads a specification source with information from a
        /// SQL database.</summary>
        ///--------------------------------------------------------------------------------
        public void LoadSpecificationSource()
        {
            try
            {
                switch (DatabaseTypeCode)
                {
                case (int)BLL.Config.DatabaseTypeCode.SqlServer:
                    Database sqlDatabase = null;

                    Server sqlServer;
                    if (SourceDbServerName.StartsWith("(localdb)", StringComparison.OrdinalIgnoreCase))
                    {
                        var conn = new ServerConnection(new SqlConnection(String.Format("server={0};integrated security=true", SourceDbServerName)));
                        sqlServer = new Server(conn);
                        sqlServer.SetDefaultInitFields(true);
                    }
                    else
                    {
                        sqlServer = new Server(SourceDbServerName);
                        sqlServer.SetDefaultInitFields(true);
                        if (!String.IsNullOrEmpty(PasswordClearText) && !String.IsNullOrEmpty(UserName))
                        {
                            // sql server authentication
                            sqlServer.ConnectionContext.LoginSecure = false;
                            sqlServer.ConnectionContext.Login       = UserName;
                            sqlServer.ConnectionContext.Password    = PasswordClearText;
                        }
                        else
                        {
                            // windows authentication
                            sqlServer.ConnectionContext.LoginSecure = true;
                        }
                    }
                    sqlServer.ConnectionContext.Connect();
                    if (sqlServer.ConnectionContext.IsOpen == false)
                    {
                        SpecDatabase = null;
                        ApplicationException ex = new ApplicationException(String.Format(DisplayValues.Exception_SourceDbServerConnection, SourceDbServerName));
                        Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
                        throw ex;
                    }

                    if (SourceDbName.Contains("\\"))
                    {
                        var dbName = Path.GetFileNameWithoutExtension(SourceDbName);
                        sqlDatabase = sqlServer.Databases[dbName];

                        if (sqlDatabase == null)
                        {
                            // attach the database instead of opening the database by name
                            var stringColl = new StringCollection();
                            stringColl.Add(SourceDbName);
                            stringColl.Add(Path.Combine(Path.GetDirectoryName(SourceDbName), Path.GetFileNameWithoutExtension(SourceDbName) + "_log.ldf"));

                            sqlServer.AttachDatabase(dbName, stringColl);

                            sqlDatabase = sqlServer.Databases[SourceDbName];
                        }
                    }
                    else
                    {
                        sqlDatabase = sqlServer.Databases[SourceDbName];
                    }

                    if (sqlDatabase == null)
                    {
                        SpecDatabase = null;
                        ApplicationException ex = new ApplicationException(String.Format(DisplayValues.Exception_SourceDbNotFound, SourceDbName, SourceDbServerName));
                        Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
                        throw ex;
                    }
                    else
                    {
                        // load the database information
                        SpecDatabase = new SqlDatabase();
                        SpecDatabase.SqlDatabaseID = Guid.NewGuid();
                        SpecDatabase.Solution      = Solution;
                        SpecDatabase.LoadSqlServerDatabase(sqlDatabase);
                    }
                    break;

                case (int)BLL.Config.DatabaseTypeCode.MySQL:
                    string myConnectionString = "SERVER=" + SourceDbServerName + ";" +
                                                "DATABASE=" + SourceDbName + ";" +
                                                "UID=" + UserName + ";" +
                                                "PASSWORD="******";";
                    MySqlConnection connection = new MySqlConnection(myConnectionString);
                    using (connection)
                    {
                        try
                        {
                            connection.Open();
                        }
                        catch
                        {
                            SpecDatabase = null;
                            ApplicationException ex = new ApplicationException(String.Format(DisplayValues.Exception_MySQLConnection, SourceDbName, SourceDbServerName));
                            Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
                            throw;
                        }
                        // load the database information
                        SpecDatabase = new SqlDatabase();
                        SpecDatabase.SqlDatabaseID = Guid.NewGuid();
                        SpecDatabase.Solution      = Solution;
                        SpecDatabase.LoadMySQLDatabase(connection);
                        connection.Close();
                    }
                    break;

                default:
                    throw new NotImplementedException("DatabaseTypeCode value " + DatabaseTypeCode + " not implemented!");
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                Solution.ShowIssue(ex.ToString());
            }
        }