Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In tabular mode the concept of database is similar to those concepts in relational engine and multidimensional models; the database is the container of all objects in the tabular model.
Database Representation
The database is the place where all objects that form a tabular model reside. Contained by the database the developer finds objects like connections, tables, roles and many more.
Database in AMO
When using AMO to manage a Tabular Model database, the Database object in AMO matches one-to-one the database logical object in a tabular model.
Note
In order to gain access to a database object, in AMO, the user needs to have access to a server object and connect to it.
Database in ADOMD.Net
When using ADOMD to consult and query a Tabular Model database, the sense of using or being connected to a specific database is obtained through the AdomdConnection object.
You can connect directly to a certain database using the following code snipped:
using ADOMD = Microsoft.AnalysisServices.AdomdClient;
…
ADOMD.AdomdConnection currrentCnx = new ADOMD.AdomdConnection("Data Source=<<server\instance>>;Catalog=<<database>>");
currrentCnx.Open();
…
Also, over an existing connection object (that hasn't been closed) you can change the current database to another of your choice as shown in the following code snippet:
currentCnx.ChangeDatabase("myOtherDatabase");
Database in AMO
When using AMO to manage a database object you start first with a Server object and from there you search for your database in the databases collection or create a new database by adding one to the collection.
The following code snippet shows the steps to connect to a server and how to create an empty database, after checking the database doesn’t exist:
AMO.Server CurrentServer = new AMO.Server();
try
{
CurrentServer.Connect(currentServerName);
}
catch (Exception cnxException)
{
MessageBox.Show(string.Format("Error while trying to connect to server: [{0}]\nError message: {1}", currentServerName, cnxException.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
newDatabaseName = DatabaseName.Text;
if (CurrentServer.Databases.Contains(newDatabaseName))
{
return;
}
try
{
AMO.Database newDatabase = CurrentServer.Databases.Add(newDatabaseName);
CurrentServer.Update();
}
catch (Exception createDBxc)
{
MessageBox.Show(String.Format("Database [{0}] couldn't be created.\n{1}", newDatabaseName, createDBxc.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
newDatabaseAvailable = false;
}
Also, if you want to have a practical understanding on how to use AMO to create and manipulate database representations see the source code of the AMO2Tabular sample; specifically check in the following source file: Database.cs. The sample is available at Codeplex. An important note about the code: the code is provided only as a support to the logical concepts explained here and should not be used in a production environment; nor should it be used for other purpose other than the pedagogical one.