Showing posts with label sample. Show all posts
Showing posts with label sample. Show all posts

Sunday, March 25, 2012

Analysis Service Connection Pooling

In SQL Server documentation it is mentioned that the SP3 Code sample contains
the Analysis Service Connection Pooling sample. Please help me in locating
the code sample.
Thanks in advance.
Manoj
http://msdn.microsoft.com/library/de...onnpooling.asp
Dave Wickert [MSFT]
dwickert@.online.microsoft.com
Program Manager
BI SystemsTeam
SQL BI Product Unit (Analysis Services)
This posting is provided "AS IS" with no warranties, and confers no rights.
"Manoj" <Manoj@.discussions.microsoft.com> wrote in message
news:AF17E419-ED8D-4E97-AA3D-76A06BCFD465@.microsoft.com...
> In SQL Server documentation it is mentioned that the SP3 Code sample
contains
> the Analysis Service Connection Pooling sample. Please help me in locating
> the code sample.
> Thanks in advance.
> Manoj

Saturday, February 25, 2012

AmoAdventureWorks sample problems.

Can execute the above sample (on XP Pro SP2) successfully once. Subsequent attempts result in error below(after grabbing all system resources for a few minutes). Tried deleting the database and then stop starting the server before retrying - to no avail.

Kind of sapping my confidence in AMO objects.

Any ideas?

Thanks in advance

Zub

--

Unhandled Exception: System.Data.OleDb.OleDbException: Deferred prepare could no

t be completed.

Query timeout expired

at System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr)

at System.Data.OleDb.OleDbDataReader.BuildSchemaTableRowset(Object handle)

at System.Data.OleDb.OleDbDataReader.GenerateSchemaTable(OleDbDataReader data

Reader, Object handle, CommandBehavior behavior)

at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behav

ior, String method)

at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(Comman

dBehavior behavior)

at System.Data.Common.DbDataAdapter.FillSchemaInternal(DataSet dataset, DataT

able datatable, SchemaType schemaType, IDbCommand command, String srcTable, Comm

andBehavior behavior)

at System.Data.Common.DbDataAdapter.FillSchema(DataSet dataSet, SchemaType sc

hemaType, IDbCommand command, String srcTable, CommandBehavior behavior)

at System.Data.Common.DbDataAdapter.FillSchema(DataSet dataSet, SchemaType sc

hemaType, String srcTable)

at Microsoft.Samples.SqlServer.Program.AddTable(DataSourceView dsv, OleDbConn

ection connection, String tableName) in AmoAdventure

Works\Program.cs:line 239

at Microsoft.Samples.SqlServer.Program.CreateDataSourceView(Database db) in AmoAdventureWorks\Program.cs:line 211

at Microsoft.Samples.SqlServer.Program.CreateAndProcessDatabase(Server svr) in AmoAdventureWorks\Program.cs:line 72

at Microsoft.Samples.SqlServer.Program.Main() in

AmoAdventureWorks\Program.cs:line 48

The sample application assumes you have installed SQL Server on the same machine you have your Analysis Server.

And you have attached sample AdventureWorksDW SQL database. Search for "connectionString" in your project and you be able to point it to any SQL Server you have AdventureWorksDW database.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Edward I'm not sure what you are suggesting.

I have SQL Server Anaylsis Server and AMOAdventureWorks.exe all running on the same machine.

The point is that it works once. The AS database is created, cubes defined and populated. The problem is that subsequent exceutions fail.

Thanks

Zub

|||

The error message suggests problems with connecting to relational database.

AMOAdventureWorks creates a AS database and populates it with data from SQL server you installed locally. Is it possible that SQL server was unavalible?

I've tried to run AMOAdventureWorks several times. And it worked without a problem.

Try running it in the debugger and see exactly where it fails.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Edward

Thanks for the response.

OK I'm debugging.

Rebooted machine. Ran the program once - it succeeded.

Second time I get a IndexOutofRangeException on the line

DataTable dataTable = dataTables[0];

in

static void AddTable(DataSourceView dsv, OleDbConnection connection, String tableName)

{

OleDbDataAdapter adapter = new OleDbDataAdapter(

"SELECT * FROM [dbo].[" + tableName + "] WHERE 1=0",

connection);

DataTable[] dataTables = adapter.FillSchema(dsv.Schema,

SchemaType.Mapped, tableName);

DataTable dataTable = dataTables[0];

......

when called from

AddTable(dsv, connection, "DimCustomer");

rgds

Zub

|||

Couple things I notice in the code.

1) It works the first time but not the second time. Does your table name exist in DB when you pass in second time?

2) If you pass same table name on second time, it does not make sense because DimCustomer is already in dsv.Schema after you call it first time. This is redundent.

Try replacing with following lines and see if you can get the table everytime you call.

DataSet dataSet = new DataSet();

DataTable[] dataTables = adapter.FillSchema(dataSet,

SchemaType.Mapped, tableName);

3) Anyway, you don't use any AMO object except in the line of doing FillSchema. If you still have problem as my suggestion in Step 2, then it must be the connection problem. Check if the table exists in the DB and valid permission to access that table as well.

|||

Sorry I just notice one more thing.

You got Query time out error on second time. Is your table a big table or a complicated view when you call second time? It seems that it took a lot of time to execute the statement. You may want to increase the connection time out in your connection or set it to unlimited.

Also, you can try the same SQL Statement "Select * from [dbo].[DimCustomer] where 1=0" as New query in SQL Management studio. See how long it takes to get the result.

AMO:How to do ProcessPartition by using AMO

Hi All,

i need a sample code how we can do process the partition by using AMO.

Please send the sample code.

Hi there,

You can take a look here for some sample code..

Chris.
|||

Hi,

Another sample code here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=516918&SiteID=1

AMO: Merging Partitions

Does anybody have a sample AMO code for merging two existing partitions through AMO? Please help.

Thanks,

Nagy

Copied from http://technet.microsoft.com/en-us/library/ms345091.aspx

Merging Partitions

Merging partitions means performing any operation that results in two or more partitions becoming one partition.

Merging partitions is a method of the Partition object. This command merges the data of one or more source partitions into a target partition and deletes the source partitions.

Partitions can be merged only if they meet all the following criteria:

Partitions are in the same measure group.
Partitions are stored in the same mode (MOLAP, HOLAP, and ROLAP).
Partitions reside on the same server; remote partitions can be merged if on the same server.
|||

Thanks for your reply Adrian. This merges all the partitions in a measure group into one. What is the code to merge Partition_a with Partition_b when my measure group has Partition_a, Partition_b, Partition_c, Partition_d?

Regards,

Nagy

|||

If you want to merge A and B into A, create an array of size 1 with B and call Merge on partition A with that array.

The Merge method will merge the specified collection of Partitions (the sources) into the Partition on which is called (the destination).

Adrian Dumitrascu

Friday, February 24, 2012

AMO with VB.Net

Hi All,

I am working on a project that require me to build cubes programmatically i.e., using AMO object and VB.Net. I am trying to find a sample that builds cubes using VB.Net.

I can add further features to it based on the sample.

Can any one help me at their earliest?

Thanks

Sekhar PC

Check the following two links:

http://www.asptoday.com/Content.aspx?id=2351

and

http://sorosjing.cnblogs.com/archive/2005/12/08/292848.html

Have fun.

Yones

|||

Hi,

Thank you for your reply.

When I tried to create a cube by exactly following the sample, always it threw an error "Could not deploy the cube".

Is there a better sample that help to create cube using AMO and dotnet? A sample that get deployed though the source is AdventureWorks only.

Thanks

SekharPC

|||

Thanks for the reply.

When I tried to implement the steps given in the above listed website, everytime I got an error message saying "Could not create cubes". Then I copied and pasted and tried to create cubes using AdventureWorks database. Still the error continued.

Can a better sample be found which I can use to create my cubes dynamically?

An early reply will be of great help to me.

Thanks

SekharPC

|||

There is great C# sample in http://msdn2.microsoft.com/en-us/library/ms345091.aspx

it was very useful for me.

Mohsen

AMO with VB.Net

Hi All,

I am working on a project that require me to build cubes programmatically i.e., using AMO object and VB.Net. I am trying to find a sample that builds cubes using VB.Net.

I can add further features to it based on the sample.

Can any one help me at their earliest?

Thanks

Sekhar PC

Check the following two links:

http://www.asptoday.com/Content.aspx?id=2351

and

http://sorosjing.cnblogs.com/archive/2005/12/08/292848.html

Have fun.

Yones

|||

Hi,

Thank you for your reply.

When I tried to create a cube by exactly following the sample, always it threw an error "Could not deploy the cube".

Is there a better sample that help to create cube using AMO and dotnet? A sample that get deployed though the source is AdventureWorks only.

Thanks

SekharPC

|||

Thanks for the reply.

When I tried to implement the steps given in the above listed website, everytime I got an error message saying "Could not create cubes". Then I copied and pasted and tried to create cubes using AdventureWorks database. Still the error continued.

Can a better sample be found which I can use to create my cubes dynamically?

An early reply will be of great help to me.

Thanks

SekharPC

|||

There is great C# sample in http://msdn2.microsoft.com/en-us/library/ms345091.aspx

it was very useful for me.

Mohsen

AMO with VB.Net

Hi All,

I am working on a project that require me to build cubes programmatically i.e., using AMO object and VB.Net. I am trying to find a sample that builds cubes using VB.Net.

I can add further features to it based on the sample.

Can any one help me at their earliest?

Thanks

Sekhar PC

Check the following two links:

http://www.asptoday.com/Content.aspx?id=2351

and

http://sorosjing.cnblogs.com/archive/2005/12/08/292848.html

Have fun.

Yones

|||

Hi,

Thank you for your reply.

When I tried to create a cube by exactly following the sample, always it threw an error "Could not deploy the cube".

Is there a better sample that help to create cube using AMO and dotnet? A sample that get deployed though the source is AdventureWorks only.

Thanks

SekharPC

|||

Thanks for the reply.

When I tried to implement the steps given in the above listed website, everytime I got an error message saying "Could not create cubes". Then I copied and pasted and tried to create cubes using AdventureWorks database. Still the error continued.

Can a better sample be found which I can use to create my cubes dynamically?

An early reply will be of great help to me.

Thanks

SekharPC

|||

There is great C# sample in http://msdn2.microsoft.com/en-us/library/ms345091.aspx

it was very useful for me.

Mohsen

AMO with VB.Net

Hi All,

I am working on a project that require me to build cubes programmatically i.e., using AMO object and VB.Net. I am trying to find a sample that builds cubes using VB.Net.

I can add further features to it based on the sample.

Can any one help me at their earliest?

Thanks

Sekhar PC

Check the following two links:

http://www.asptoday.com/Content.aspx?id=2351

and

http://sorosjing.cnblogs.com/archive/2005/12/08/292848.html

Have fun.

Yones

|||

Hi,

Thank you for your reply.

When I tried to create a cube by exactly following the sample, always it threw an error "Could not deploy the cube".

Is there a better sample that help to create cube using AMO and dotnet? A sample that get deployed though the source is AdventureWorks only.

Thanks

SekharPC

|||

Thanks for the reply.

When I tried to implement the steps given in the above listed website, everytime I got an error message saying "Could not create cubes". Then I copied and pasted and tried to create cubes using AdventureWorks database. Still the error continued.

Can a better sample be found which I can use to create my cubes dynamically?

An early reply will be of great help to me.

Thanks

SekharPC

|||

There is great C# sample in http://msdn2.microsoft.com/en-us/library/ms345091.aspx

it was very useful for me.

Mohsen

AMO created cube and Calculated Measures

I'm using AMO (based on the Adventure Works sample) to create a simple cube. I create it with a Measure Group named BaseFact that has 2 measures, Dollar Sales (DOLSLS) and Package Sales (PKGSLS). The cube create works and I can see the correct values for each of the measures when I browse it in Management Studio connected to Analysis Services.

To continue with the cube (and my education) I want to dynamically add a calculated measure or two. The forums seem to suggest that this is not possible using AMO and suggest using the cubes MdxScript to create calculated measures.

I used script to new query window to look at the XMLA script for the cube. There is no MdxScripts section in the XML text. If I look at the cube in the debugger it shows the MdxScripts collection count to be 0. After running the code below to get an MdxScript object, add new commands and update the cube I can again look at the XMLA for the cube and now there is a MdxScript with only the new measures I created. The measures also show up when I browse the cube. However, I can no longer see any data for the original measures or the added measures. I'd appreciate any help in understanding what is happening.

Server srv = new Server();
srv.Connect("localhost");
Database db = srv.Databases["MyCube"];
Cube cb = db.Cubes["MyCube"];
MdxScript ms = cb.MdxScripts.Add();
string cmd = "CREATE MEMBER CurrentCube.Measures.Price as [Measures].[DOLSLS] / [Measures].[PKGSLS]";
ms.Commands.Add(new Command(cmd));
cmd = "CREATE MEMBER CurrentCube.Measures.MyMem2 as [Measures].[Price] * 2";
ms.Commands.Add(new Command(cmd));
cmd = "CREATE MEMBER CurrentCube.Measures.MyMem3 as [Measures].[Price] * 3";
ms.Commands.Add(new Command(cmd));

ms.Update();
cb.Update();
cb.Process();
srv.Dispose();

Thanks
John

Solved it.
1. Added semi-colon to end of strings.
2. I thought I had read somewhere in the forums that the CALCULATE as the first command was optional but it isn't. Added the CALUCULATE and it all works.

John

AMO created cube and Calculated Measures

I'm using AMO (based on the Adventure Works sample) to create a simple cube. I create it with a Measure Group named BaseFact that has 2 measures, Dollar Sales (DOLSLS) and Package Sales (PKGSLS). The cube create works and I can see the correct values for each of the measures when I browse it in Management Studio connected to Analysis Services.

To continue with the cube (and my education) I want to dynamically add a calculated measure or two. The forums seem to suggest that this is not possible using AMO and suggest using the cubes MdxScript to create calculated measures.

I used script to new query window to look at the XMLA script for the cube. There is no MdxScripts section in the XML text. If I look at the cube in the debugger it shows the MdxScripts collection count to be 0. After running the code below to get an MdxScript object, add new commands and update the cube I can again look at the XMLA for the cube and now there is a MdxScript with only the new measures I created. The measures also show up when I browse the cube. However, I can no longer see any data for the original measures or the added measures. I'd appreciate any help in understanding what is happening.

Server srv = new Server();
srv.Connect("localhost");
Database db = srv.Databases["MyCube"];
Cube cb = db.Cubes["MyCube"];
MdxScript ms = cb.MdxScripts.Add();
string cmd = "CREATE MEMBER CurrentCube.Measures.Price as [Measures].[DOLSLS] / [Measures].[PKGSLS]";
ms.Commands.Add(new Command(cmd));
cmd = "CREATE MEMBER CurrentCube.Measures.MyMem2 as [Measures].[Price] * 2";
ms.Commands.Add(new Command(cmd));
cmd = "CREATE MEMBER CurrentCube.Measures.MyMem3 as [Measures].[Price] * 3";
ms.Commands.Add(new Command(cmd));

ms.Update();
cb.Update();
cb.Process();
srv.Dispose();

Thanks
John

Solved it.
1. Added semi-colon to end of strings.
2. I thought I had read somewhere in the forums that the CALCULATE as the first command was optional but it isn't. Added the CALUCULATE and it all works.

John

AMO Browser Sample

Hey guys,

Since I'm new to SQL Server 2005, I was testing some Samples that came with it. Now, I'm having problems with the AMO Browser....
everytime I run it, it gives me the connection and the AMO Browser pop-ups but when I try to connect (Analysis Services Server: Data Source=localhost)

It gives me an error:

A connection cannot be made. Ensure that the server is running

Additional Information:

No connection could be made because the target machine actively refused it (System)
Show Technical details
All Messages:
===================================

A connection cannot be made. Ensure that the server is running. (Microsoft.AnalysisServices)


Program Location:

at Microsoft.AnalysisServices.XmlaClient.GetTcpClient(ConnectionInfo connectionInfo)
at Microsoft.AnalysisServices.XmlaClient.OpenTcpConnection(ConnectionInfo connectionInfo)
at Microsoft.AnalysisServices.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
at Microsoft.AnalysisServices.Server.Connect(String connectionString, String sessionId)
at Microsoft.AnalysisServices.Server.Connect(String connectionString)
at Microsoft.Samples.SqlServer.AmoBrowser.connectButton_Click(Object sender, EventArgs e)

===================================

No connection could be made because the target machine actively refused it (System)


Program Location:

at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
at Microsoft.AnalysisServices.XmlaClient.GetTcpClientByAddress(String hostName, Int32 port)
at Microsoft.AnalysisServices.XmlaClient.GetTcpClient(ConnectionInfo connectionInfo)


* My server is running for all Services and Databases!

Could anyone please help me out on this one, I'm not sure if anyone have tried this already. Thanks in advance!

hi,i have the same question!|||

First check whether the SQL SERVER ANALYSIS SERVICES 2005 WAS INSTALLED

IF installed and check whether it is running or not IN Background

AMO Browser Sample

Hey guys,

Since I'm new to SQL Server 2005, I was testing some Samples that came with it. Now, I'm having problems with the AMO Browser....
everytime I run it, it gives me the connection and the AMO Browser pop-ups but when I try to connect (Analysis Services Server: Data Source=localhost)

It gives me an error:

A connection cannot be made. Ensure that the server is running

Additional Information:

No connection could be made because the target machine actively refused it (System)
Show Technical details
All Messages:
===================================

A connection cannot be made. Ensure that the server is running. (Microsoft.AnalysisServices)


Program Location:

at Microsoft.AnalysisServices.XmlaClient.GetTcpClient(ConnectionInfo connectionInfo)
at Microsoft.AnalysisServices.XmlaClient.OpenTcpConnection(ConnectionInfo connectionInfo)
at Microsoft.AnalysisServices.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
at Microsoft.AnalysisServices.Server.Connect(String connectionString, String sessionId)
at Microsoft.AnalysisServices.Server.Connect(String connectionString)
at Microsoft.Samples.SqlServer.AmoBrowser.connectButton_Click(Object sender, EventArgs e)

===================================

No connection could be made because the target machine actively refused it (System)


Program Location:

at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
at Microsoft.AnalysisServices.XmlaClient.GetTcpClientByAddress(String hostName, Int32 port)
at Microsoft.AnalysisServices.XmlaClient.GetTcpClient(ConnectionInfo connectionInfo)


* My server is running for all Services and Databases!

Could anyone please help me out on this one, I'm not sure if anyone have tried this already. Thanks in advance!

hi,i have the same question!|||

First check whether the SQL SERVER ANALYSIS SERVICES 2005 WAS INSTALLED

IF installed and check whether it is running or not IN Background

AMO Browser Sample

Hey guys,

Since I'm new to SQL Server 2005, I was testing some Samples that came with it. Now, I'm having problems with the AMO Browser....
everytime I run it, it gives me the connection and the AMO Browser pop-ups but when I try to connect (Analysis Services Server: Data Source=localhost)

It gives me an error:

A connection cannot be made. Ensure that the server is running

Additional Information:

No connection could be made because the target machine actively refused it (System)
Show Technical details
All Messages:
===================================

A connection cannot be made. Ensure that the server is running. (Microsoft.AnalysisServices)


Program Location:

at Microsoft.AnalysisServices.XmlaClient.GetTcpClient(ConnectionInfo connectionInfo)
at Microsoft.AnalysisServices.XmlaClient.OpenTcpConnection(ConnectionInfo connectionInfo)
at Microsoft.AnalysisServices.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
at Microsoft.AnalysisServices.Server.Connect(String connectionString, String sessionId)
at Microsoft.AnalysisServices.Server.Connect(String connectionString)
at Microsoft.Samples.SqlServer.AmoBrowser.connectButton_Click(Object sender, EventArgs e)

===================================

No connection could be made because the target machine actively refused it (System)


Program Location:

at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
at Microsoft.AnalysisServices.XmlaClient.GetTcpClientByAddress(String hostName, Int32 port)
at Microsoft.AnalysisServices.XmlaClient.GetTcpClient(ConnectionInfo connectionInfo)


* My server is running for all Services and Databases!

Could anyone please help me out on this one, I'm not sure if anyone have tried this already. Thanks in advance!

hi,i have the same question!|||

First check whether the SQL SERVER ANALYSIS SERVICES 2005 WAS INSTALLED

IF installed and check whether it is running or not IN Background

AMO "Scripter" Class - Help

Has anyone ever used Microsoft.AnalysisServices.Scripter class to programtically script SSAS objects? I am looking for a little bit of sample code to get me started. My goal here is to script some of the SSAS objects out into XML and store the XML in a table that can be queried to produce some meta data reports. I plan on doing this using AMO inside of a Script Task of a SSIS package.

So here are my two main questions:

    Can anyone provide me with some sample code (I am not that good with .NET) using the Scripter class to script an SSAS object? Can anyone tell me a better way to build reports based on the meta data of my SSAS objects?

Thank you in advance!

Here is some sample code to use Scripter to script Alter command for your database into a file. You can later have SSIS to load content of the file into a table.

using Microsoft.AnalysisServices;

........

XmlTextWriter xmlwrite = new XmlTextWriter( "MyDatabase.XMLA", System.Text.Encoding.UTF8);

xmlwrite.Formatting = Formatting.Indented;

xmlwrite.Indentation = 2;

Scripter.WriteAlter(xmlwrite, myDataBase, true, true);

xmlwrite.Close();

|||

Edward,

Thanks for the code sample. This should do the trick. However, I have one more follow up question for you. How do I write the XML into a String variabe instead of to a file? Thanks again.

|||

Take a look at the functionality provided to you by XMLTextWriter.

http://msdn2.microsoft.com/en-us/system.xml.xmltextwriter.aspx

You shoudl be able to use different constructor for it.Search for sample of using XMLTextWriter.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Edward,

Thanks again for the help. Here is the code that I came up with, it is in VB.NET and will work inside of a SSIS Script Task. It should help anyone trying to do the same thing. Thanks you for your help on this one.

' Microsoft SQL Server Integration Services Script Task

' Write scripts using Microsoft Visual Basic

' The ScriptMain class is the entry point of the Script Task.

Imports System

Imports System.IO

Imports System.Data

Imports System.Math

Imports System.Xml

Imports System.Data.SqlClient

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.AnalysisServices

Class ScriptMain

Public Sub Main()

' Get Server and Database name from DTS connection object

Dim oDTSASConnection As ConnectionManager = Dts.Connections("AS Server")

Dim sASServer As String = CStr(oDTSASConnection.Properties("ServerName").GetValue(oDTSASConnection))

Dim oASServer As New Microsoft.AnalysisServices.Server

' Connect to the requested server

oASServer.Connect(sASServer)

' Loop trough all of the dbs on the server and write xmla to db

Dim oASDatabase As New Microsoft.AnalysisServices.Database

For Each oASDatabase In oASServer.Databases

Call ScriptASDatabase(oASServer, oASDatabase)

'' Loop trough all of the cubes in the db and write xmla to db

Dim oASCube As New Microsoft.AnalysisServices.Cube

For Each oASCube In oASDatabase.Cubes

Call ScriptASCube(oASServer, oASDatabase, oASCube)

Next

' Loop trough all of the dimensions in the db and write xmla to db

Dim oASDim As New Microsoft.AnalysisServices.Dimension

For Each oASDim In oASDatabase.Dimensions

Call ScriptASDim(oASServer, oASDatabase, oASDim)

Next

Next

' Clean Up

oASServer.Disconnect()

Dts.TaskResult = Dts.Results.Success

End Sub

Public Sub ScriptASDatabase(ByVal oASServer As Microsoft.AnalysisServices.Server, ByVal oASDatabase As Microsoft.AnalysisServices.Database)

' Create wrtiters and set formating for xml

Dim stringWriter As New System.IO.StringWriter()

Dim xmlWriter As New System.Xml.XmlTextWriter(stringWriter)

xmlWriter.Formatting = Formatting.Indented

xmlWriter.Indentation = 2

Dim sXMLA As String

' Script dbs on the server and write to db

Scripter.WriteCreate(xmlWriter, oASServer, oASDatabase, False, False)

sXMLA = stringWriter.ToString

Call DBUpsert(oASServer.Name.ToString, oASDatabase.Name.ToString, oASDatabase.Name.ToString, oASDatabase.ID.ToString, oASDatabase.ID.ToString, "Database", sXMLA.ToString)

' Clean Up

stringWriter.Close()

xmlWriter.Close()

End Sub

Public Sub ScriptASCube(ByVal oASServer As Microsoft.AnalysisServices.Server, ByVal oASDatabase As Microsoft.AnalysisServices.Database, ByVal oASCube As Microsoft.AnalysisServices.Cube)

'Create wrtiters and set formating for xml

Dim stringWriter As New System.IO.StringWriter()

Dim xmlWriter As New System.Xml.XmlTextWriter(stringWriter)

xmlWriter.Formatting = Formatting.Indented

xmlWriter.Indentation = 2

Dim sXMLA As String

' Script cubes in the db and write to db

Scripter.WriteCreate(xmlWriter, oASDatabase, oASCube, False, False)

sXMLA = stringWriter.ToString

Call DBUpsert(oASServer.Name.ToString, oASDatabase.Name.ToString, oASCube.Name.ToString, oASCube.ID.ToString, oASCube.Parent.ID.ToString, "Cube", sXMLA.ToString)

' Clean Up

stringWriter.Close()

xmlWriter.Close()

End Sub

Public Sub ScriptASDim(ByVal oASServer As Microsoft.AnalysisServices.Server, ByVal oASDatabase As Microsoft.AnalysisServices.Database, ByVal oASDim As Microsoft.AnalysisServices.Dimension)

'Create wrtiters and set formating for xml

Dim stringWriter As New System.IO.StringWriter()

Dim xmlWriter As New System.Xml.XmlTextWriter(stringWriter)

xmlWriter.Formatting = Formatting.Indented

xmlWriter.Indentation = 2

Dim sXMLA As String

' Script cubes in the db and write to db

Scripter.WriteCreate(xmlWriter, oASDatabase, oASDim, True, False)

sXMLA = stringWriter.ToString

Call DBUpsert(oASServer.Name.ToString, oASDatabase.Name.ToString, oASDim.Name.ToString, oASDim.ID.ToString, oASDim.Parent.ID.ToString, "Dimension", sXMLA.ToString)

' Clean Up

stringWriter.Close()

xmlWriter.Close()

End Sub

Public Sub DBUpsert(ByVal sASServer As String, ByVal sASDatabase As String, ByVal sASName As String, ByVal sID As String, ByVal sParentID As String, ByVal sObjectType As String, ByVal sXMLA As String)

' Create a connection to the db

Dim oDTSDBConnection As Microsoft.SqlServer.Dts.Runtime.ConnectionManager = Dts.Connections("Local.MetaData")

Dim sDBServer As String = CStr(oDTSDBConnection.Properties("ServerName").GetValue(oDTSDBConnection))

Dim sDBDatabase As String = CStr(oDTSDBConnection.Properties("InitialCatalog").GetValue(oDTSDBConnection))

Dim oBuilder As New SqlConnectionStringBuilder()

oBuilder.DataSource = sDBServer

oBuilder.InitialCatalog = sDBDatabase

oBuilder.ConnectTimeout = 1000

oBuilder.IntegratedSecurity = True

oBuilder.ApplicationName = "ImportSSASXml"

Dim oDBConnection As New SqlConnection(oBuilder.ConnectionString.ToString)

' Create Sql Command

Dim cmd As New SqlCommand("dbo.etl_ImportSSASXml", oDBConnection)

cmd.CommandTimeout = 60

cmd.Connection = oDBConnection

cmd.CommandType = CommandType.StoredProcedure

' Add parameters and their values

cmd.Parameters.Add(New SqlParameter("@.Server", SqlDbType.VarChar, 255)).Value = sASServer

cmd.Parameters.Add(New SqlParameter("@.Database", SqlDbType.VarChar, 255)).Value = sASDatabase

cmd.Parameters.Add(New SqlParameter("@.Name", SqlDbType.VarChar, 255)).Value = sASName

cmd.Parameters.Add(New SqlParameter("@.ID", SqlDbType.VarChar, 255)).Value = sID

cmd.Parameters.Add(New SqlParameter("@.ParentID", SqlDbType.VarChar, 255)).Value = sParentID

cmd.Parameters.Add(New SqlParameter("@.ObjectType", SqlDbType.VarChar, 255)).Value = sObjectType

cmd.Parameters.Add(New SqlParameter("@.XMLA", SqlDbType.VarChar)).Value = sXMLA

' Open the connection

oDBConnection.Open()

' Execute the command

cmd.ExecuteNonQuery()

' Clean Up

oDBConnection.Close()

End Sub

End Class

I will be posting a comprehensive solution to building meta data reports on/about ones' SSAS objects on my blog in the next few weeks. Check it out if you are interested!