/// <summary>
        /// Connects to a SQL Server 2016 Analysis Services instance and loads a tabular model
        /// from one of the deployed databases on the instance.
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseName"></param>
        public TabularModelHandler(string serverName, string databaseName, TabularModelHandlerSettings settings = null)
        {
            this.serverName = serverName;
            _disableUpdates = true;

            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = new TOM.Server();

            var connectionString = TabularConnection.GetConnectionString(serverName, applicationName);

            server.Connect(connectionString);

            if (databaseName == null)
            {
                if (server.Databases.Count >= 1)
                {
                    database = server.Databases[0];
                }
                else
                {
                    throw new InvalidOperationException("This instance does not contain any databases, or the user does not have access.");
                }
            }
            else
            {
                database = server.Databases.GetByName(databaseName);
            }
            if (CompatibilityLevel < 1200)
            {
                throw new InvalidOperationException("Only databases with Compatibility Level 1200 or higher can be loaded in Tabular Editor.");
            }

            SourceType = ModelSourceType.Database;
            Source     = database.Server.Name + "." + database.Name;

            Status  = "Connected succesfully.";
            Version = database.Version;
            Init();

            Model.ClearTabularEditorAnnotations();

            _disableUpdates     = false;
            UndoManager.Enabled = true;
            PowerBIGovernance.UpdateGovernanceMode(this);
            CheckErrors();

            trace = new ExternalChangeTrace(database, applicationName, XEventCallback);
            if (Settings.ChangeDetectionLocalServers)
            {
                trace.Start();
            }
        }
Пример #2
0
        /// <summary>
        /// Connects to a SQL Server 2016 Analysis Services instance and loads a tabular model
        /// from one of the deployed databases on the instance.
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseName"></param>
        public TabularModelHandler(string serverName, string databaseName, TabularModelHandlerSettings settings = null) : this(settings)
        {
            this.serverName = serverName;
            _disableUpdates = true;

            server = new TOM.Server();

            var connectionString = TabularConnection.GetConnectionString(serverName, applicationName);
            server.Connect(connectionString);

            if (string.IsNullOrEmpty(databaseName))
            {
                if (server.Databases.Count >= 1)
                {
                    database = server.Databases[0];
                }
                else
                {
                    throw new InvalidOperationException("This instance does not contain any databases, or the user does not have access.");
                }
            }
            else
            {
                database = server.Databases.FindByName(databaseName);
                if (database == null)
                {
                    database = server.Databases[databaseName];
                }
            }
            if (CompatibilityLevel < 1200)
            {
                throw new InvalidOperationException("Only databases with Compatibility Level 1200 or higher can be loaded in Tabular Editor.");
            }

            SourceType = ModelSourceType.Database;
            Source     = database.Server.Name + "." + database.Name;

            Status  = "Connected successfully.";
            Version = database.Version;
            Init();
            UndoManager.Suspend();

            Model.ClearTabularEditorAnnotations();

            _disableUpdates = false;
            UndoManager.Resume();
            PowerBIGovernance.UpdateGovernanceMode();
            CheckErrors();

            try
            {
                ExternalChangeTrace.Cleanup();
                trace = new ExternalChangeTrace(database, applicationName, XEventCallback);
                if (Settings.ChangeDetectionLocalServers)
                {
                    trace.Start();
                }
            }
            catch (Exception ex)
            {
                Log("Exception while configuring AS trace: " + ex.Message);
            }
        }