Пример #1
0
        private Microsoft.DataWarehouse.Design.DataSourceConnection GetOpenedDataSourceConnection(DataSource dataSource)
        {
            Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = Microsoft.DataWarehouse.DataWarehouseUtilities.GetOpenedDataSourceConnection((object)null, dataSource.ID, dataSource.Name, dataSource.ManagedProvider, dataSource.ConnectionString, dataSource.Site, false);
            try
            {
                if (openedDataSourceConnection != null)
                {
                    openedDataSourceConnection.QueryTimeOut = (int)dataSource.Timeout.TotalSeconds;
                }
            }
            catch { }

            if (openedDataSourceConnection == null)
            {
                MessageBox.Show("Unable to connect to data source [" + dataSource.Name + "]");
                return(null);
            }
            else if (!(openedDataSourceConnection.ConnectionObject is System.Data.OleDb.OleDbConnection))
            {
                MessageBox.Show("Data source [" + dataSource.Name + "] is not an OLEDB connection. Only OLEDB connections are supported currently.");
                return(null);
            }

            return(openedDataSourceConnection);
        }
Пример #2
0
        private void ExecDSV(ProjectItem pi)
        {
            try
            {
                //close all project windows
                foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                {
                    bool bIsOpen = piTemp.get_IsOpen(BIDSViewKinds.Designer);
                    if (bIsOpen)
                    {
                        Window win = piTemp.Open(BIDSViewKinds.Designer);
                        win.Close(vsSaveChanges.vsSaveChangesYes);
                    }
                }

                DataSourceView dsv = pi.Object as DataSourceView;

                Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = GetOpenedDataSourceConnection(dsv.DataSource);

                Program.SQLFlattener = new frmSQLFlattener();
                Program.SQLFlattener.txtServer.Text       = openedDataSourceConnection.DataSource;
                Program.SQLFlattener.cmbDatabase.Items[0] = openedDataSourceConnection.Database;
                Program.SQLFlattener.Conn = (System.Data.OleDb.OleDbConnection)openedDataSourceConnection.ConnectionObject;
                Program.SQLFlattener.cmbTable.Items[0] = string.Empty;
                Program.SQLFlattener.cmbID.Items[0]    = string.Empty;
                Program.SQLFlattener.cmbPID.Items[0]   = string.Empty;
                Program.SQLFlattener.dsv = dsv;
                Program.SQLFlattener.DataSourceConnection = openedDataSourceConnection;

                Program.ASFlattener = null;

                if (Program.SQLFlattener.ShowDialog() == DialogResult.OK)
                {
                    Window winDesigner = pi.Open(BIDSViewKinds.Designer);
                    winDesigner.Activate();
                    System.ComponentModel.Design.IDesignerHost           host     = (System.ComponentModel.Design.IDesignerHost)(winDesigner.Object);
                    Microsoft.AnalysisServices.Design.DataSourceDesigner designer = (Microsoft.AnalysisServices.Design.DataSourceDesigner)host.GetDesigner(dsv);
                    designer.MakeDesignerDirty();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
Пример #3
0
        private static string DBServerName = ""; //will say Oracle or Microsoft SQL Server

        private DimensionError[] Check(Dimension d)
        {
            if (d.MiningModelID != null)
            {
                return new DimensionError[] { }
            }
            ;
            List <DimensionError> problems = new List <DimensionError>();
            //TODO: need to add in code to allow you to cancel such that it will stop an executing query

            DataSource dataSource = d.DataSource;

            try
            {
                //if the key attribute points to a table with a different data source than the default data source for the DSV, use it
                ColumnBinding col = GetColumnBindingForDataItem(d.KeyAttribute.KeyColumns[0]);

                DataTable table = d.DataSourceView.Schema.Tables[col.TableID];
                if (table.ExtendedProperties.ContainsKey("DataSourceID"))
                {
                    dataSource = d.Parent.DataSources[table.ExtendedProperties["DataSourceID"].ToString()];
                }
            }
            catch { }

            Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = Microsoft.DataWarehouse.DataWarehouseUtilities.GetOpenedDataSourceConnection((object)null, dataSource.ID, dataSource.Name, dataSource.ManagedProvider, dataSource.ConnectionString, dataSource.Site, false);
            try
            {
                if (openedDataSourceConnection != null)
                {
                    openedDataSourceConnection.QueryTimeOut = (int)dataSource.Timeout.TotalSeconds;
                }
            }
            catch { }

            if (openedDataSourceConnection == null)
            {
                DimensionError err = new DimensionError();
                err.ErrorDescription = "Unable to connect to data source [" + dataSource.Name + "] to test attribute relationships and key uniqueness.";
                problems.Add(err);
            }
            else
            {
                sq           = openedDataSourceConnection.Cartridge.IdentStartQuote;
                fq           = openedDataSourceConnection.Cartridge.IdentEndQuote;
                DBServerName = openedDataSourceConnection.DBServerName;
                cartridge    = openedDataSourceConnection.Cartridge;

                int    iProgressCount = 0;
                String sql            = "";
                bool   bGotSQL        = false;
                foreach (DimensionAttribute da in d.Attributes)
                {
                    try
                    {
                        bGotSQL = false;
                        if (da.Usage != AttributeUsage.Parent)
                        {
                            sql = GetQueryToValidateKeyUniqueness(da);
                        }
                        else
                        {
                            sql = null;
                        }
                        if (sql != null)
                        {
                            bGotSQL = true;
                            DataSet ds = new DataSet();
                            openedDataSourceConnection.Fill(ds, sql);
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                string             problem = "Attribute [" + da.Name + "] has key values with multiple names.";
                                DimensionDataError err     = new DimensionDataError();
                                err.ErrorDescription = problem;
                                err.ErrorTable       = ds.Tables[0];
                                problems.Add(err);
                            }
                        }
                        ApplicationObject.StatusBar.Progress(true, "Checking Attribute Key Uniqueness...", ++iProgressCount, d.Attributes.Count * 2);
                    }
                    catch (Exception ex)
                    {
                        string         problem = "Attempt to validate key and name relationship for attribute [" + da.Name + "] failed:" + ex.Message + ex.StackTrace + (bGotSQL ? "\r\nSQL query was: " + sql : "");
                        DimensionError err     = new DimensionError();
                        err.ErrorDescription = problem;
                        problems.Add(err);
                    }
                }
                foreach (DimensionAttribute da in d.Attributes)
                {
                    foreach (AttributeRelationship r in da.AttributeRelationships)
                    {
                        try
                        {
                            bGotSQL = false;
                            if (da.Usage != AttributeUsage.Parent)
                            {
                                sql = GetQueryToValidateRelationship(r);
                            }
                            else
                            {
                                sql = null;
                            }
                            if (sql != null)
                            {
                                bGotSQL = true;
                                DataSet ds = new DataSet();
                                openedDataSourceConnection.Fill(ds, sql);
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    string             problem = "Attribute relationship [" + da.Name + "] -> [" + r.Attribute.Name + "] is not valid because it results in a many-to-many relationship.";
                                    DimensionDataError err     = new DimensionDataError();
                                    err.ErrorDescription = problem;
                                    err.ErrorTable       = ds.Tables[0];
                                    problems.Add(err);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string         problem = "Attempt to validate attribute relationship [" + da.Name + "] -> [" + r.Attribute.Name + "] failed:" + ex.Message + ex.StackTrace + (bGotSQL ? "\r\nSQL query was: " + sql : "");
                            DimensionError err     = new DimensionError();
                            err.ErrorDescription = problem;
                            problems.Add(err);
                        }
                    }
                    ApplicationObject.StatusBar.Progress(true, "Checking Attribute Relationships...", ++iProgressCount, d.Attributes.Count * 2);
                }
                cartridge = null;
                openedDataSourceConnection.Close();
            }

            //check obvious attribute relationship mistakes
            foreach (DimensionAttribute da in d.Attributes)
            {
                foreach (DimensionAttribute child in d.Attributes)
                {
                    try
                    {
                        if (child.ID != da.ID && da.AttributeHierarchyEnabled && ContainsSubsetOfKeys(da, child) && !IsParentOf(child, da))
                        {
                            if (ContainsSubsetOfKeys(child, da) && (IsParentOf(da, child) || (child.Name.CompareTo(da.Name) < 0 && child.AttributeHierarchyEnabled)))
                            {
                                //if the keys for both are the same, then skip this one if the opposite attribute relationship is defined... otherwise, only return one direction based on alphabetic order
                                continue;
                            }

                            DimensionRelationshipWarning warn = new DimensionRelationshipWarning();
                            if (d.KeyAttribute.AttributeRelationships.Contains(child.ID))
                            {
                                warn.ErrorDescription = "Attribute [" + child.Name + "] has a subset of the keys of attribute [" + da.Name + "]. Therefore, those attributes can be related which is preferable to leaving [" + child.Name + "] related directly to the key.";
                            }
                            else
                            {
                                warn.ErrorDescription = "Attribute [" + child.Name + "] has a subset of the keys of attribute [" + da.Name + "]. Therefore, those attributes can be related. However, this may not be necessary since [" + child.Name + "] is already part of a set of attribute relationships.";
                            }

                            warn.Attribute        = da;
                            warn.RelatedAttribute = child;
                            problems.Add(warn);
                        }
                    }
                    catch (Exception ex)
                    {
                        string         problem = "Attempt to check for obvious attribute relationship oversights on [" + da.Name + "] and [" + child.Name + "] failed:" + ex.Message + ex.StackTrace;
                        DimensionError err     = new DimensionError();
                        err.ErrorDescription = problem;
                        problems.Add(err);
                    }
                }
            }

            return(problems.ToArray());
        }
Пример #4
0
        private void ExecDimension(ProjectItem pi)
        {
            try
            {
                Dimension dim = pi.Object as Dimension;
                Program.ASFlattener     = new frmASFlattener();
                Program.ASFlattener.dim = dim;
                frmASFlattenerOptions Options = new frmASFlattenerOptions();
                Options.lbHierarchies.Items.Clear();
                Options.lbAttributes.Items.Clear();
                if (dim != null)
                {
                    foreach (Hierarchy hier in dim.Hierarchies)
                    {
                        Options.lbHierarchies.Items.Add(new ctlFancyCheckedListBoxItem(hier.Name, true));
                    }
                    foreach (DimensionAttribute attr in dim.Attributes)
                    {
                        if (attr.Usage == AttributeUsage.Regular)
                        {
                            if (ASPCDimNaturalizer.IsAttributeRelated(attr, dim.KeyAttribute))
                            {
                                Options.lbAttributes.Items.Add(attr.Name);
                            }
                            Options.lbHierarchies.Items.Add(new ctlFancyCheckedListBoxItem(attr.Name, false));
                        }
                    }
                }

                for (int i = 0; i < Options.lbAttributes.Items.Count; i++)
                {
                    Options.lbAttributes.SetItemChecked(i, true);
                }
                for (int i = 0; i < Options.lbHierarchies.Items.Count; i++)
                {
                    Options.lbHierarchies.SetItemChecked(i, true);
                }
                Options.tabControl1.SelectedIndex = 0;
                Options.numMinLevels.Value        = 0;
                Options.trkActionLevel.Value      = 4;

                if (Options.ShowDialog() == DialogResult.OK)
                {
                    ProjectItem piDsv = null;
                    foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                    {
                        if (piTemp.Object == dim.DataSourceView)
                        {
                            piDsv = piTemp;
                            break;
                        }
                    }

                    //close all project windows
                    foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
                    {
                        bool bIsOpen = piTemp.get_IsOpen(BIDSViewKinds.Designer);
                        if (bIsOpen)
                        {
                            Window win = piTemp.Open(BIDSViewKinds.Designer);
                            win.Close(vsSaveChanges.vsSaveChangesYes);
                        }
                    }

                    Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = GetOpenedDataSourceConnection(dim.DataSource);
                    Program.ASFlattener.db = Program.ASFlattener.dim.Parent;
                    Program.ASFlattener.DataSourceConnection = openedDataSourceConnection;

                    Program.SQLFlattener = null;

                    asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy       projectService = (asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectHierarchy));
                    sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings       = (sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)pi.ContainingProject).GetService(typeof(sharedDataWarehouseInterfaces::Microsoft.DataWarehouse.Interfaces.IConfigurationSettings));
                    asAlias::Microsoft.DataWarehouse.Project.DataWarehouseProjectManager projectManager = (asAlias::Microsoft.DataWarehouse.Project.DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null);

                    Dimension dimNew = dim.Clone();
                    dimNew.Name = dim.Name + "_Naturalized";
                    dimNew.ID   = dimNew.Name;

                    string sNewDimProjectItemName = dimNew.Name + ".dim";
                    if (dim.ParentServer != null)
                    {
                        sNewDimProjectItemName = dimNew.Name;
                    }
                    if (dim.Parent.Dimensions.ContainsName(dimNew.Name))
                    {
                        projectManager.GetProjectItemFromName(sNewDimProjectItemName).Delete(); //deletes the project item and the dimension from the AMO dimensions collection
                    }

                    if (dim.ParentServer == null)
                    {
                        string sFullPath = pi.get_FileNames(0);
                        sFullPath = sFullPath.Substring(0, sFullPath.Length - System.IO.Path.GetFileName(sFullPath).Length) + sNewDimProjectItemName;
                        XmlWriter writer = new System.Xml.XmlTextWriter(sFullPath, Encoding.UTF8);
                        Microsoft.AnalysisServices.Utils.Serialize(writer, dimNew, false);
                        writer.Close();

                        asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectNode parentNode = null;
                        asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.IFileProjectNode projNode   = projectManager.CreateFileProjectNode(ref parentNode, 1, sNewDimProjectItemName, sFullPath, 0, 0);

                        projectService.Add(projNode, parentNode);
                        ((asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.ComponentModel.IFileProjectComponentManager)projectManager).UpdateComponentModel(asAlias::Microsoft.DataWarehouse.VsIntegration.Shell.Project.ComponentModel.UpdateOperationType.AddObject, projNode);
                    }
                    else
                    {
                        dim.Parent.Dimensions.Add(dimNew);
                    }

                    Program.Progress = new frmProgress();
                    Program.Progress.ShowDialog(); // The Progress form actually launches the naturalizer...

                    if (piDsv != null && dim.ParentServer == null)
                    {
                        Window winDesigner = piDsv.Open(BIDSViewKinds.Designer);
                        winDesigner.Activate();
                        System.ComponentModel.Design.IDesignerHost host = (System.ComponentModel.Design.IDesignerHost)(winDesigner.Object);
                        asAlias::Microsoft.AnalysisServices.Design.DataSourceDesigner designer = (asAlias::Microsoft.AnalysisServices.Design.DataSourceDesigner)host.GetDesigner(dim.DataSourceView);
                        designer.MakeDesignerDirty();
                    }

                    ProjectItem piNew = projectManager.GetProjectItemFromName(sNewDimProjectItemName);
                    if (dim.ParentServer == null)
                    {
                        piNew.Save(null);
                        //piNew.ContainingProject.Save(null); //didn't work
                    }
                    else
                    {
                        //already processed inside the ASPCDimNaturalizer code
                    }

                    Window winNew = piNew.Open(BIDSViewKinds.Designer);
                    winNew.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        internal static int SyncDescriptions(Dimension d, bool bPromptForProperties, IServiceProvider provider, bool bIsTabular)
        {
            int        iUpdatedDescriptions = 0;
            DataSource dataSource           = d.DataSource;

            ColumnBinding colDimensionKey = null;

#if DENALI || SQL2014
            if (d.KeyAttribute.KeyColumns[0].Source is RowNumberBinding)
            {
                foreach (DimensionAttribute a in d.Attributes)
                {
                    if (a.KeyColumns != null && a.KeyColumns.Count > 0 && a.KeyColumns[0].Source is ColumnBinding)
                    {
                        colDimensionKey = GetColumnBindingForDataItem(a.KeyColumns[0]);
                        break;
                    }
                }
                if (colDimensionKey == null)
                {
                    throw new Exception("Couldn't find an attribute with a ColumnBinding, so couldn't find DSV table.");
                }
            }
            else
            {
                colDimensionKey = GetColumnBindingForDataItem(d.KeyAttribute.KeyColumns[0]);
            }
#else
            colDimensionKey = GetColumnBindingForDataItem(d.KeyAttribute.KeyColumns[0]);
#endif

            DataTable oDimensionKeyTable = d.DataSourceView.Schema.Tables[colDimensionKey.TableID];

            //if this is a Tabular model, the Dimension.DataSource may point at the default data source for the data source view
            if (oDimensionKeyTable.ExtendedProperties.ContainsKey("DataSourceID"))
            {
                dataSource = d.Parent.DataSources[oDimensionKeyTable.ExtendedProperties["DataSourceID"].ToString()];
            }

            IServiceProvider settingService = dataSource.Site;
            if (settingService == null)
            {
                settingService = provider;
            }

            Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = Microsoft.DataWarehouse.DataWarehouseUtilities.GetOpenedDataSourceConnection((object)null, dataSource.ID, dataSource.Name, dataSource.ManagedProvider, dataSource.ConnectionString, settingService, false);
            try
            {
                if (d.MiningModelID != null)
                {
                    return(iUpdatedDescriptions);
                }

                try
                {
                    if (openedDataSourceConnection != null)
                    {
                        openedDataSourceConnection.QueryTimeOut = (int)dataSource.Timeout.TotalSeconds;
                    }
                }
                catch { }

                if (openedDataSourceConnection == null)
                {
                    throw new Exception("Unable to connect to data source [" + d.DataSource.Name + "].");
                }
                else
                {
                    sq           = openedDataSourceConnection.Cartridge.IdentStartQuote;
                    fq           = openedDataSourceConnection.Cartridge.IdentEndQuote;
                    DBServerName = openedDataSourceConnection.DBServerName;
                    cartridge    = openedDataSourceConnection.Cartridge;

                    if (DBServerName != "Microsoft SQL Server")
                    {
                        MessageBox.Show("Data source [" + d.DataSource.Name + "] connects to " + DBServerName + " which may not be supported.");
                    }

                    String sql = "select distinct Name from sys.extended_properties order by Name";

                    if (bPromptForProperties)
                    {
                        DataSet dsExtendedProperties = new DataSet();
                        openedDataSourceConnection.Fill(dsExtendedProperties, sql);

                        BIDSHelper.SSAS.SyncDescriptionsForm form = new BIDSHelper.SSAS.SyncDescriptionsForm();
                        form.cmbDescriptionProperty.DataSource    = dsExtendedProperties.Tables[0];
                        form.cmbDescriptionProperty.DisplayMember = "Name";
                        form.cmbDescriptionProperty.ValueMember   = "Name";

                        foreach (DataRow row in dsExtendedProperties.Tables[0].Rows)
                        {
                            form.listOtherProperties.Items.Add(row["Name"].ToString());
                        }

                        DialogResult result = form.ShowDialog();

                        if (result != DialogResult.OK)
                        {
                            return(iUpdatedDescriptions);
                        }

                        DescriptionPropertyName = form.cmbDescriptionProperty.GetItemText(form.cmbDescriptionProperty.SelectedItem);
                        List <string> listOtherProperties = new List <string>();
                        for (int i = 0; i < form.listOtherProperties.CheckedItems.Count; i++)
                        {
                            listOtherProperties.Add(form.listOtherProperties.GetItemText(form.listOtherProperties.CheckedItems[i]));
                        }
                        OtherPropertyNamesToInclude   = listOtherProperties.ToArray();
                        OverwriteExistingDescriptions = form.chkOverwriteExistingDescriptions.Checked;
                    }

                    if ((string.IsNullOrEmpty(d.Description) || OverwriteExistingDescriptions) &&
                        (!oDimensionKeyTable.ExtendedProperties.ContainsKey("QueryDefinition") || bIsTabular) && //Tabular always has a QueryDefinition, even when it's just a table binding
                        oDimensionKeyTable.ExtendedProperties.ContainsKey("DbTableName") &&
                        oDimensionKeyTable.ExtendedProperties.ContainsKey("DbSchemaName"))
                    {
                        sql = "SELECT PropertyName = p.name" + "\r\n"
                              + ",PropertyValue = CAST(p.value AS sql_variant)" + "\r\n"
                              + "FROM sys.all_objects AS tbl" + "\r\n"
                              + "INNER JOIN sys.schemas sch ON sch.schema_id = tbl.schema_id" + "\r\n"
                              + "INNER JOIN sys.extended_properties AS p ON p.major_id=tbl.object_id AND p.minor_id=0 AND p.class=1" + "\r\n"
                              + "where sch.name = '" + oDimensionKeyTable.ExtendedProperties["DbSchemaName"].ToString().Replace("'", "''") + "'\r\n"
                              + "and tbl.name = '" + oDimensionKeyTable.ExtendedProperties["DbTableName"].ToString().Replace("'", "''") + "'\r\n"
                              + "order by p.name";

                        string  sNewDimensionDescription = "";
                        DataSet dsTableProperties        = new DataSet();
                        openedDataSourceConnection.Fill(dsTableProperties, sql);

                        foreach (DataRow row in dsTableProperties.Tables[0].Rows)
                        {
                            if (string.Compare((string)row["PropertyName"], DescriptionPropertyName, true) == 0)
                            {
                                sNewDimensionDescription = (string)row["PropertyValue"];
                            }
                        }

                        foreach (DataRow row in dsTableProperties.Tables[0].Rows)
                        {
                            foreach (string sProp in OtherPropertyNamesToInclude)
                            {
                                if (string.Compare((string)row["PropertyName"], sProp, true) == 0 && !string.IsNullOrEmpty((string)row["PropertyValue"]))
                                {
                                    if (sNewDimensionDescription.Length > 0)
                                    {
                                        sNewDimensionDescription += "\r\n";
                                    }
                                    sNewDimensionDescription += (string)row["PropertyName"] + ": " + (string)row["PropertyValue"];
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(sNewDimensionDescription))
                        {
                            d.Description = sNewDimensionDescription;
                            iUpdatedDescriptions++;
                        }
                    }

                    foreach (DimensionAttribute a in d.Attributes)
                    {
                        ColumnBinding col = null;

#if DENALI || SQL2014
                        if (a.Type == AttributeType.RowNumber)
                        {
                            continue;
                        }
#endif
                        if (a.NameColumn != null)
                        {
                            if (!(a.NameColumn.Source is ColumnBinding))
                            {
                                continue;
                            }
                            col = GetColumnBindingForDataItem(a.NameColumn);
                        }
                        else if (a.KeyColumns.Count == 1)
                        {
                            if (!(a.KeyColumns[0].Source is ColumnBinding))
                            {
                                continue;
                            }
                            col = GetColumnBindingForDataItem(a.KeyColumns[0]);
                        }
                        else
                        {
                            continue; //skip this attribute since we don't know which column to use
                        }
                        DataTable oDsvTable = d.DataSourceView.Schema.Tables[col.TableID];

                        if ((string.IsNullOrEmpty(a.Description) || OverwriteExistingDescriptions) &&
                            (!oDsvTable.ExtendedProperties.ContainsKey("QueryDefinition") || bIsTabular) &&
                            oDsvTable.ExtendedProperties.ContainsKey("DbTableName") &&
                            oDsvTable.ExtendedProperties.ContainsKey("DbSchemaName"))
                        {
                            sql = "SELECT PropertyName = p.name" + "\r\n"
                                  + ",PropertyValue = CAST(p.value AS sql_variant)" + "\r\n"
                                  + "FROM sys.all_objects AS tbl" + "\r\n"
                                  + "INNER JOIN sys.schemas sch ON sch.schema_id = tbl.schema_id" + "\r\n"
                                  + "INNER JOIN sys.all_columns AS clmns ON clmns.object_id=tbl.object_id" + "\r\n"
                                  + "INNER JOIN sys.extended_properties AS p ON p.major_id=clmns.object_id AND p.minor_id=clmns.column_id AND p.class=1" + "\r\n"
                                  + "where sch.name = '" + oDsvTable.ExtendedProperties["DbSchemaName"].ToString().Replace("'", "''") + "'\r\n"
                                  + "and tbl.name = '" + oDsvTable.ExtendedProperties["DbTableName"].ToString().Replace("'", "''") + "'\r\n"
                                  + "and clmns.name = '" + oDsvTable.Columns[col.ColumnID].ColumnName.Replace("'", "''") + "'\r\n"
                                  + "order by p.name";

                            string  sNewDescription = "";
                            DataSet dsProperties    = new DataSet();
                            openedDataSourceConnection.Fill(dsProperties, sql);

                            foreach (DataRow row in dsProperties.Tables[0].Rows)
                            {
                                if (string.Compare((string)row["PropertyName"], DescriptionPropertyName, true) == 0)
                                {
                                    sNewDescription = (string)row["PropertyValue"];
                                }
                            }

                            foreach (DataRow row in dsProperties.Tables[0].Rows)
                            {
                                foreach (string sProp in OtherPropertyNamesToInclude)
                                {
                                    if (string.Compare((string)row["PropertyName"], sProp, true) == 0 && !string.IsNullOrEmpty((string)row["PropertyValue"]))
                                    {
                                        if (sNewDescription.Length > 0)
                                        {
                                            sNewDescription += "\r\n";
                                        }
                                        sNewDescription += (string)row["PropertyName"] + ": " + (string)row["PropertyValue"];
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(sNewDescription))
                            {
                                a.Description = sNewDescription;
                                iUpdatedDescriptions++;
                            }
                        }
                    }


                    if (d.Site != null) //if not Tabular
                    {
                        //mark dimension as dirty
                        IComponentChangeService changesvc = (IComponentChangeService)d.Site.GetService(typeof(IComponentChangeService));
                        changesvc.OnComponentChanging(d, null);
                        changesvc.OnComponentChanged(d, null, null, null);
                    }
                }
            }
            finally
            {
                try
                {
                    cartridge = null;
                    openedDataSourceConnection.Close();
                }
                catch { }
            }
            return(iUpdatedDescriptions);
        }