public static string GetTMSL(TOM.Database db, TOM.Server server, string targetDatabaseID, DeploymentOptions options, bool includeRestricted = false)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (string.IsNullOrWhiteSpace(targetDatabaseID))
            {
                throw new ArgumentNullException("targetDatabaseID");
            }
            if (options.DeployRoleMembers && !options.DeployRoles)
            {
                throw new ArgumentException("Cannot deploy Role Members when Role deployment is disabled.");
            }

            if (server.Databases.Contains(targetDatabaseID) && options.DeployMode == DeploymentMode.CreateDatabase)
            {
                throw new ArgumentException("The specified database already exists.");
            }

            string tmsl;

            db.AddTabularEditorTag();
            if (!server.Databases.Contains(targetDatabaseID))
            {
                tmsl = DeployNewTMSL(db, targetDatabaseID, options, includeRestricted);
            }
            else
            {
                tmsl = DeployExistingTMSL(db, server, targetDatabaseID, options, includeRestricted);
            }
            db.RemoveTabularEditorTag();

            return(tmsl);
        }
Exemple #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="databaseId"></param>
        public TabularModelHandler(string serverName, string databaseId, TabularModelHandlerSettings settings = null)
        {
            this.serverName = serverName;
            _disableUpdates = true;

            Settings = settings ?? TabularModelHandlerSettings.Default;

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

            if (databaseId == 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[databaseId];
            }
            database.RemoveTabularEditorTag();
            CompatibilityLevel = database.CompatibilityLevel;

            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);
        }