Databases Reference
In-Depth Information
ADOMD.NET Connections
In a typical data access system, the first step is to establish a connection to a source of
data. A client application that works with Microsoft SQL Server Analysis Services follows
the same rule, and establishes a connection to the data source. To establish this connec-
tion, ADOMD.NET provides the class
AdomdConnection
, which is similar to the connection
classes of
SqlClient
,
OledbClient
, and other ADO.NET providers.
AdomdConnection
implements the
IDBConnection
interface and supports the majority of
methods defined by the interface, as shown in Figure 33.5.
System.Data.IDBConnection
AdomdClient.AdomdConnection
FIGURE 33.5
The ADOMDConnection object implements the IDBConnection interface.
As shown in Listing 33.1, the client application uses the
ConnectionString
properly of
AdomdConnection
class to specify information needed to make a connection—for example,
the name of the server or of the database.
LISTING 33.1
Opening and Closing Connections
//Create a connection string with connection properties.
String conString = “Datasource=localhost; Initial Catalog=Foodmart 2008”;
// Create a connection object.
AdomdConnection con = new AdomdConnection();
//Set the connection string on the connection object.
con.ConnectionString = conString;
//Open a connection.
con.Open();
//Do the necessary operations.
//Close the connection.
con.Close();
As you can see, this code is similar to the code of an application that uses ADO DB and
ADO.NET. In designing ADOMD.NET, we did our utmost to make sure that all the object
models we provide with Analysis Services—ADOMD.NET, AMO, and the OLE DB
provider—support the same set of properties.
Search WWH ::
Custom Search