Databases Reference
In-Depth Information
object model (described in the next section of this chapter). If you like, you can skip this
example and return to it later.
LISTING 33.2
Multiple Connections Using the Same Session
//Create the first connection object.
AdomdConnection con = new AdomdConnection();
con.ConnectionString = “Datasource=localhost; Initial Catalog=Foodmart 2008;”;
con.Open();
//Create a command and send a request that will create a new calculated member
//on the session.
AdomdCommand command = con.CreateCommand();
command.CommandText = “CREATE MEMBER [Warehouse and Sales].Measures.MyCalcMember as
1”;
command.ExecuteNonQuery();
//Check to make sure that the calculated member was created.
if (null != con.Cubes[“Warehouse and Sales”].Measures.Find(“MyCalcMember”))
Console.WriteLine(“ Measure 'MyCalcMember' is created on the session from the
first connection. “);
else
Console.WriteLine(“ Measure 'MyCalcMember' is not created on the session from
the firstconnection. “);
//Create the second connection object.
AdomdConnection con2 = new AdomdConnection();
con2.ConnectionString = “Datasource=localhost; Initial Catalog=Foodmart 2008;”;
//Set the session identifier of the first connection in the second
//connection object.
con2.SessionID = con.SessionID;
// Open the second connection
con2.Open();
//Check to make sure that the calculated member created by first connection
//is available on the second connection.
if (null != con2.Cubes[“Warehouse and Sales”].Measures.Find(“MyCalcMember”))
Console.WriteLine(“ Measure 'MyCalcMember' is available on the session from
the second connection. “);
else
Console.WriteLine(“ Measure 'MyCalcMember' is not available on the session
from the second connection. “);
//Close the second connection.
con2.Close();
Search WWH ::




Custom Search