Beispiel #1
0
        public static void LoadFromSMO(MSMO.Database database, Guid databaseID, ExpandMask.TableExpandSetting tableExpandSetting)
        {
#if TRACE
            long startTicks = VNC.AppLog.Trace3("Enter", LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 0);
#endif
            SQLInformation.Data.ApplicationDataSet.DBTablesRow dataRow = null;

            MarkExistingItemsAsNotFound(databaseID);    // This enables cleanup of items that once existed but were deleted.

            foreach (MSMO.Table table in database.Tables)
            {
                if (table.IsSystemObject)
                {
                    continue;   // Skip System Tables
                }

                dataRow          = GetInfoFromSMO(table, databaseID, tableExpandSetting);
                dataRow.NotFound = false;

                if (dataRow.ExpandColumns)
                {
                    try
                    {
                        TableColumn.LoadFromSMO(table, dataRow.ID);
                    }
                    catch (Exception ex)
                    {
                        ReportException(ex, dataRow, CLASS_BASE_ERRORNUMBER + 1);
                        //VNC.AppLog.Error(ex, LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 1);
                    }
                }

                try
                {
                    TableTrigger.LoadFromSMO(table, dataRow.ID);
                }
                catch (Exception ex)
                {
                    ReportException(ex, dataRow, CLASS_BASE_ERRORNUMBER + 2);
                    //VNC.AppLog.Error(ex, LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 2);
                }
            }

            Common.ApplicationDataSet.DBTablesTA.Update(Common.ApplicationDataSet.DBTables);
#if TRACE
            VNC.AppLog.Trace3("Exit", LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 3, startTicks);
#endif
        }
Beispiel #2
0
        public static void LoadFromSMO(MSMO.Server server, Guid instanceID, ExpandMask.DatabaseExpandSetting databaseExpandSettings)
        {
#if TRACE
            long startTicks = VNC.AppLog.Trace2("Enter", LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 0);
#endif
            long stopwatchFrequency = Stopwatch.Frequency;

            MarkExistingItemsAsNotFound(instanceID);    // This enables cleanup of items that once existed but were deleted.

            foreach (MSMO.Database database in server.Databases)
            {
                long loopStartTicks = Stopwatch.GetTimestamp();

                if (!database.IsAccessible)
                {
                    VNC.AppLog.Warning(string.Format("Database: {0} is not accessible, skipping", database.Name), LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 1);
                    continue;
                }

                SQLInformation.Data.ApplicationDataSet.DatabasesRow databaseRow = GetInfoFromSMO(instanceID, server.Name, database);
                databaseRow.NotFound = false;

                try
                {
                    if (databaseRow.IsMonitored && databaseExpandSettings.IsMonitored)
                    {
                        if (databaseRow.ExpandStoredProcedures && databaseExpandSettings.ExpandStoredProcedures)
                        {
                            StoredProcedure.LoadFromSMO(database, databaseRow.ID);
                        }

                        if (databaseRow.ExpandTables && databaseExpandSettings.ExpandTables)
                        {
                            ExpandMask.TableExpandSetting tableExpandSetting = new ExpandMask.TableExpandSetting(databaseRow.DefaultTableExpandMask);
                            Table.LoadFromSMO(database, databaseRow.ID, tableExpandSetting);
                        }

                        if (databaseRow.ExpandViews && databaseExpandSettings.ExpandViews)
                        {
                            ExpandMask.ViewExpandSetting viewExpandSetting = new ExpandMask.ViewExpandSetting(databaseRow.DefaultViewExpandMask);
                            View.LoadFromSMO(database, databaseRow.ID, viewExpandSetting);
                        }

                        if (databaseRow.ExpandFileGroups && databaseExpandSettings.ExpandFileGroups)
                        {
                            FileGroup.LoadFromSMO(database, databaseRow.ID);
                        }

                        if (databaseRow.ExpandLogFiles && databaseExpandSettings.ExpandLogFiles)
                        {
                            LogFile.LoadFromSMO(database, databaseRow.ID);
                        }

                        if (databaseRow.ExpandRoles && databaseExpandSettings.ExpandRoles)
                        {
                            DatabaseRole.LoadFromSMO(database, databaseRow.ID);
                        }

                        if (databaseRow.ExpandTriggers && databaseExpandSettings.ExpandTriggers)
                        {
                            DatabaseDdlTrigger.LoadFromSMO(database, databaseRow.ID);
                        }

                        if (databaseRow.ExpandUserDefinedFunctions && databaseExpandSettings.ExpandUserDefinedFunctions)
                        {
                            UserDefinedFunction.LoadFromSMO(database, databaseRow.ID);
                        }

                        if (databaseRow.ExpandUsers && databaseExpandSettings.ExpandUsers)
                        {
                            User.LoadFromSMO(database, databaseRow.ID, databaseRow.Name_Database);
                        }
                    }
                }
                catch (Exception ex)
                {
                    VNC.AppLog.Error(ex, LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 2);
                }

                databaseRow.SnapShotDuration = (Stopwatch.GetTimestamp() - loopStartTicks) / stopwatchFrequency;
                Common.ApplicationDataSet.DatabasesTA.Update(Common.ApplicationDataSet.Databases);
            }

#if TRACE
            VNC.AppLog.Trace2("Exit", LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 3, startTicks);
#endif
        }
Beispiel #3
0
        private static SQLInformation.Data.ApplicationDataSet.DBTablesRow GetInfoFromSMO(MSMO.Table table, Guid databaseID, ExpandMask.TableExpandSetting tableExpandSetting)
        {
#if TRACE
            long startTicks = VNC.AppLog.Trace4(string.Format("Enter {0}", table.Name), LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 4);
#endif
            SQLInformation.Data.ApplicationDataSet.DBTablesRow dataRow = null;

            try
            {
                var dbs = from tb in Common.ApplicationDataSet.DBTables
                          where tb.Database_ID == databaseID
                          select tb;

                var dbs2 = from db2 in dbs
                           where db2.Name_Table == table.Name
                           select db2;

                if (dbs2.Count() > 0)
                {
                    dataRow = dbs2.First();
                    Update(table, dataRow);
                }
                else
                {
                    dataRow = Add(databaseID, table, tableExpandSetting);
                }
            }
            catch (Exception ex)
            {
                ReportException(ex, dataRow, CLASS_BASE_ERRORNUMBER + 5);
                //VNC.AppLog.Error(ex, LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 5);
            }

#if TRACE
            VNC.AppLog.Trace4(string.Format("Exit {0}", table.Name), LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 6, startTicks);
#endif
            return(dataRow);
        }
Beispiel #4
0
        private static SQLInformation.Data.ApplicationDataSet.DBTablesRow Add(Guid databaseID, MSMO.Table table, ExpandMask.TableExpandSetting tableExpandSetting)
        {
            SQLInformation.Data.ApplicationDataSet.DBTablesRow dataRow = null;

            try
            {
                dataRow             = Common.ApplicationDataSet.DBTables.NewDBTablesRow();
                dataRow.ID          = Guid.NewGuid();
                dataRow.Database_ID = databaseID;  // From above

                dataRow.Name_Table = table.Name;
                dataRow.CreateDate = table.CreateDate;

                try
                {
                    dataRow.DataSpaceUsed = table.DataSpaceUsed;
                }
                catch (Exception ex)
                {
#if TRACE
                    VNC.AppLog.Debug(ex.ToString(), LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 7);
#endif
                    dataRow.DataSpaceUsed = -1;
                }

                try
                {
                    dataRow.DateLastModified = table.DateLastModified;
                }
                catch (Exception ex)
                {
#if TRACE
                    VNC.AppLog.Debug(ex.ToString(), LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 7);
#endif
                }

                dataRow.FileGroup = table.FileGroup;
                dataRow.HasIndex  = table.HasIndex;
                dataRow.Owner     = table.Owner;
                dataRow.RowCount  = table.RowCount;  // TODO(crhodes): Fix DB Schema to match
                dataRow.Table_ID  = table.ID.ToString();

                dataRow.ExpandColumns = tableExpandSetting.ExpandColumns;

                dataRow.SnapShotDate  = DateTime.Now;
                dataRow.SnapShotError = "";

                Common.ApplicationDataSet.DBTables_Add(dataRow);

                //Common.ApplicationDataSet.DBTables.AddDBTablesRow(dataRow);

                //Common.ApplicationDataSet.DBTablesTA.Update(Common.ApplicationDataSet.DBTables);

                // TODO(crhodes) extract Extended Properties
            }
            catch (Exception ex)
            {
                ReportException(ex, dataRow, CLASS_BASE_ERRORNUMBER + 8);
                //VNC.AppLog.Error(ex, LOG_APPNAME, CLASS_BASE_ERRORNUMBER + 8);
                // TODO(crhodes):
                // Wrap anything above that throws an exception that we want to ignore,
                // e.g. property not available because of SQL Edition.

                //UpdateDatabaseWithSnapShot(dataRow, ex.ToString().Substring(0, 256));
            }

            return(dataRow);
        }