To list down the tables in the DSV (and views, and named queries) and their columns using AMO, we use DataSourceView class. First we get the DSV directly from the cube, like this:
DataSourceView DSV1 = Cube1.DataSourceView;
Then we loop around each table on the DSV, like this:
for (int i = 0; i <= DSV1.Schema.Tables.Count – 1; i++)
{
}
And inside that loop we retrieve the table names (or named query names) using “DbTableName” Extended Property, like this:
F.WriteLine(DSV.Schema.Tables[i].ExtendedProperties[“DbTableName”]);
Notes:
- Instead of writing to file or screen, we can assign to arrays for later processing.
- Extended property: If you browse it on Local variables, the ExtendedProperties are here: DSV > Schema > Table > Non Public members > List > n > ExtendedProperties
- DSV.Schema.Tables[i].TableName contains the element name, not the named query name.
- FriendlyName extended property is changable in SSAS DSV (select the view/table, right click, properties – see below). Some cube designer use this FriendlyName property to rename a view/table (not named query).
To get the SQL for that named query, we use “QueryDefinition” extended property, like this:
F.WriteLine(DSV.Schema.Tables[i].ExtendedProperties[“QueryDefinition”])
To get the column names, we loop around the columns, like this:
for (int j = 0; j <= DSV1.Schema.Tables[i].Columns.Count – 1; j++)
{ F.WriteLine(DSV1.Schema.Tables[i].Columns[j].ColumnName }
We do have DbColumnName and FriendlyName extended properties (see below left). The values of DbColumnName are the same as ColumnName, but FriendlyName is changable (see column property in SSAS DSV screen, below right). The “design-time-name” ExtendedProperties contains a GUID.
We can also get the data type for each column, as well as max length and ordinal, like this:
DSV1.Schema.Tables[i].Columns[j].DataType
DSV1.Schema.Tables[i].Columns[j].MaxLength
DSV1.Schema.Tables[i].Columns[j].Ordinal
To add a column we use Add method, giving 2 parameters: column name and data type, like this:
DSV.Schema.Tables[i].Columns.Add(“Column9”, System.Type.GetType(“System.Int32”));
To add a table/named query we use Add method, like this:
DSV.Schema.Tables.Add(“Table9”);
Then use the Update method to update the DSV:
DSV.Update();
Can I do this somehow in Powershell for a whole list of servers? (About 200). I’d like to list all server with their catalogs, cubes, measures etc? Thanks lots.
Comment by Reiner — 6 September 2011 @ 1:33 pm |
Yes I believe you can Reiner. Please review the code samples on these pages:
1. Get SSAS objects with AMO using C# by Sornam Kumar Muthuraj. This code gets the SSAS objects for a certain server. You can loop it for all the 200 servers that you have.
2. Get SSAS DB Properties with PowerShell and AMO by Muthusamy Anantha Kumar. Search for “Database Dimensions” on the page. This code shows how to use PowerShell programming to get the objects in an SSAS DB, such as the cubes and the dimensions.
Kind regards,
Vincent
Comment by Vincent Rainardi — 7 September 2011 @ 10:29 pm |
I appreciate your time and work!
Comment by Reiner — 9 September 2011 @ 11:25 am