示例#1
0
        /// <summary>
        /// Deploys the specified database to the specified target server and database ID, using the specified options.
        /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="targetConnectionString"></param>
        /// <param name="targetDatabaseID"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        internal static DeploymentResult Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseID, DeploymentOptions options, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(targetConnectionString))
            {
                throw new ArgumentNullException("targetConnectionString");
            }
            var s = new TOM.Server();

            s.Connect(targetConnectionString);

            var tmsl = GetTMSL(db, s, targetDatabaseID, options, true);

            cancellationToken.Register(s.CancelCommand);
            var result = s.Execute(tmsl);

            if (result.ContainsErrors)
            {
                throw new Exception(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray()));
            }

            s.Refresh();
            var deployedDB = s.Databases[targetDatabaseID];

            return
                (new DeploymentResult(
                     TabularModelHandler.CheckErrors(deployedDB).Select(t => string.Format("Error on {0}: {1}", GetName(t.Item1), t.Item2)),
                     TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.DependencyError || t.Item2 == TOM.ObjectState.EvaluationError || t.Item2 == TOM.ObjectState.SemanticError)
                     .Select(t => string.Format("Warning! Object not in \"Ready\"-state: {0} ({1})", GetName(t.Item1), t.Item2.ToString())),
                     TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.CalculationNeeded || t.Item2 == TOM.ObjectState.NoData)
                     .Select(t => string.Format("Information: Unprocessed object: {0} ({1})", GetName(t.Item1), t.Item2.ToString()))
                     ));
        }
示例#2
0
        /// <summary>
        /// Deploys the specified database to the specified target server and database ID, using the specified options.
        /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="targetConnectionString"></param>
        /// <param name="targetDatabaseName"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        internal static DeploymentResult Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseName, DeploymentOptions options, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(targetConnectionString))
            {
                throw new ArgumentNullException("targetConnectionString");
            }
            var destinationServer = new TOM.Server();

            destinationServer.Connect(targetConnectionString);
            if (!destinationServer.SupportedCompatibilityLevels.Contains(db.CompatibilityLevel.ToString()))
            {
                throw new DeploymentException($"The specified server does not support Compatibility Level {db.CompatibilityLevel}");
            }

            var tmsl = GetTMSL(db, destinationServer, targetDatabaseName, options, true);

            cancellationToken.Register(destinationServer.CancelCommand);
            var result = destinationServer.Execute(tmsl);

            if (result.ContainsErrors)
            {
                throw new DeploymentException(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray()));
            }

            // Refresh the server object to make sure we get an updated list of databases, in case a new database was made:
            destinationServer.Refresh();

            // Fully refresh the deployed database object, to make sure we get updated error messages for the full object tree:
            var deployedDB = destinationServer.Databases.GetByName(targetDatabaseName);

            deployedDB.Refresh(true);
            return(GetLastDeploymentResults(deployedDB));
        }
示例#3
0
        public static void Deploy(TOM.Database db, TOM.Server s, string targetDatabaseID, DeploymentOptions options)
        {
            var tmsl   = GetTMSL(db, s, targetDatabaseID, options, true);
            var result = s.Execute(tmsl);

            if (result.ContainsErrors)
            {
                throw new Exception(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray()));
            }

            s.Refresh();
            var deployedDB = s.Databases[targetDatabaseID];
        }
示例#4
0
        /// <summary>
        /// Deploys the specified database to the specified target server and database ID, using the specified options.
        /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="targetConnectionString"></param>
        /// <param name="targetDatabaseName"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        internal static DeploymentResult Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseName, DeploymentOptions options, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(targetConnectionString))
            {
                throw new ArgumentNullException("targetConnectionString");
            }
            var destinationServer = new TOM.Server();

            destinationServer.Connect(targetConnectionString);
            if (!destinationServer.SupportedCompatibilityLevels.Contains(db.CompatibilityLevel.ToString()))
            {
                throw new DeploymentException($"The specified server does not support Compatibility Level {db.CompatibilityLevel}");
            }

            var tmsl = GetTMSL(db, destinationServer, targetDatabaseName, options, true);

            cancellationToken.Register(destinationServer.CancelCommand);
            var result = destinationServer.Execute(tmsl);

            if (result.ContainsErrors)
            {
                throw new DeploymentException(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray()));
            }

            // Refresh the server object to make sure we get an updated list of databases, in case a new database was made:
            destinationServer.Refresh();

            // Fully refresh the deployed database object, to make sure we get updated error messages for the full object tree:
            var deployedDB = destinationServer.Databases.GetByName(targetDatabaseName);

            deployedDB.Refresh(true);
            return
                (new DeploymentResult(
                     TabularModelHandler.CheckErrors(deployedDB).Select(t => string.Format("Error on {0}: {1}", GetName(t.Item1), t.Item2)),
                     TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.DependencyError || t.Item2 == TOM.ObjectState.EvaluationError || t.Item2 == TOM.ObjectState.SemanticError)
                     .Select(t => string.Format("Warning! Object not in \"Ready\"-state: {0} ({1})", GetName(t.Item1), t.Item2.ToString())),
                     TabularModelHandler.GetObjectsNotReady(deployedDB).Where(t => t.Item2 == TOM.ObjectState.CalculationNeeded || t.Item2 == TOM.ObjectState.NoData)
                     .Select(t => string.Format("Information: Unprocessed object: {0} ({1})", GetName(t.Item1), t.Item2.ToString())),
                     destinationServer
                     ));
        }
示例#5
0
        /// <summary>
        /// Deploys the specified database to the specified target server and database ID, using the specified options.
        /// Returns a list of DAX errors (if any) on objects inside the database, in case the deployment was succesful.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="targetConnectionString"></param>
        /// <param name="targetDatabaseID"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        internal static void Deploy(TOM.Database db, string targetConnectionString, string targetDatabaseID, DeploymentOptions options)
        {
            if (string.IsNullOrWhiteSpace(targetConnectionString))
            {
                throw new ArgumentNullException("targetConnectionString");
            }
            var s = new TOM.Server();

            s.Connect(targetConnectionString);

            var tmsl   = GetTMSL(db, s, targetDatabaseID, options, true);
            var result = s.Execute(tmsl);

            if (result.ContainsErrors)
            {
                throw new Exception(string.Join("\n", result.Cast <XmlaResult>().SelectMany(r => r.Messages.Cast <XmlaMessage>().Select(m => m.Description)).ToArray()));
            }

            s.Refresh();
            var deployedDB = s.Databases[targetDatabaseID];
        }
示例#6
0
        private static void DynamicRoleCreation(string roleName,
                                                string serverAddress, string databaseId, string filterExpression)
        {
            string ConnectionString = @"Provider=MSOLAP;Data Source=" + serverAddress +
                                      @";Initial Catalog=" + databaseId + ";Integrated Security=SSPI;ImpersonationLevel = Impersonate; persist security info = True; ";
            var RoleIDNamePair = new Dictionary <int, string>();
            // Get Roles Where Rolename == 'NewlycreatedRoleName=@Param'
            var GetRolesIDXMLA = @"<Batch xmlns
=""http://schemas.microsoft.com/analysisservices/2003/engine""
Transaction=""true""><Discover xmlns = ""urn:schemas-microsoft-com:xmlanalysis""><RequestType>TMSCHEMA_ROLES</RequestType><Restrictions/><Properties/></Discover
></Batch>";
            // Take Param: @RoleName for use in XMLA to create role
            var xmlaCreateRole = @"<Batch Transaction=""false""
xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine""><Create
xmlns=""http://schemas.microsoft.com/analysisservices/2014/engine""><DatabaseID>" + databaseId + @"</DatabaseID><Roles><xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema""
xmlns:sql=""urn:schemas-microsoft-com:xmlsql""><xs:element><xs:complexType><xs:sequence><xs:element
type=""row""/></xs:sequence></xs:complexType></xs:element><xs:complexType
name=""row""><xs:sequence><xs:element name=""Name"" type=""xs:string"" sql:field=""Name""
minOccurs=""0""/><xs:element name=""Description"" type=""xs:string""
sql:field=""Description"" minOccurs=""0""/><xs:element name=""ModelPermission""
type=""xs:long"" sql:field=""ModelPermission""
minOccurs=""0""/></xs:sequence></xs:complexType></xs:schema><row xmlns=""urn:schemasmicrosoft-com:xmlanalysis:rowset""><Name>" + roleName + @"</Name><ModelPermission>2</ModelPermission></row></Ro
les></Create></Batch>";
            // Get Role ID Where Rolename == @PRoleName: XMLA??
            var objServer = new Microsoft.AnalysisServices.Tabular.Server();

            objServer.Connect(ConnectionString);
            objServer.Execute(xmlaCreateRole);
            var reader = objServer.ExecuteReader(GetRolesIDXMLA, out XmlaResultCollection
                                                 resultsOut, null, true);

            // Add all roles to Cached List
            while (reader.Read())
            {
                RoleIDNamePair.Add(int.Parse(reader[0].ToString()), reader[2].ToString());
            }
            reader.Close();
            reader.Dispose();
            var RoleIDByRoleName = "";//= RoleIDNamePair.Single(s => s.Value == roleName).Key.ToString();

            foreach (var pair in RoleIDNamePair)
            {
                if (pair.Value == roleName)
                {
                    RoleIDByRoleName = pair.Key.ToString();
                    break;
                }
            }
            var AddFilterTorole = @"<Batch Transaction=""false""
xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine""><Create
xmlns=""http://schemas.microsoft.com/analysisservices/2014/engine""><DatabaseID>" + databaseId + @"</DatabaseID><TablePermissions><xs:schema
xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:sql=""urn:schemas-microsoft-com:xmlsql""><xs:element><xs:complexType><xs:sequence><xs:element
type=""row""/></xs:sequence></xs:complexType></xs:element><xs:complexType
name=""row""><xs:sequence><xs:element name=""RoleID"" type=""xs:unsignedLong""
sql:field=""RoleID"" minOccurs=""0""/><xs:element name=""RoleID.Role"" type=""xs:string""
sql:field=""RoleID.Role"" minOccurs=""0""/><xs:element name=""TableID""
type=""xs:unsignedLong"" sql:field=""TableID"" minOccurs=""0""/><xs:element
name=""TableID.Table"" type=""xs:string"" sql:field=""TableID.Table""
minOccurs=""0""/><xs:element name=""FilterExpression"" type=""xs:string""
sql:field=""FilterExpression"" minOccurs=""0""/><xs:element name=""MetadataPermission""
type=""xs:long"" sql:field=""MetadataPermission""
minOccurs=""0""/></xs:sequence></xs:complexType></xs:schema><row xmlns=""urn:schemasmicrosoft-com:xml-analysis:rowset""><RoleID>" + RoleIDByRoleName +
                                  @"</RoleID><TableID>364</TableID><FilterExpression>" + filterExpression + @"</FilterExpression
></row></TablePermissions></Create><SequencePoint
xmlns=""http://schemas.microsoft.com/analysisservices/2014/engine""><DatabaseID>" +
                                  databaseId + @"</DatabaseID></SequencePoint></Batch>";
            var applyRoleQuery = AddFilterTorole;

            objServer.Execute(applyRoleQuery);
        }