Search code examples
c#c#-4.0mdxolapadomd.net

Difference between AdomdConnection and AdomdCommand classes


My understanding is that AdomdConnection initializes a connection with a remote database. This class opens it based upon the ConnectionString. The AdomdCommand then seems capable of setting a CommandText and Executing said command, similar to executing a query.

Is this understanding correct? But how are the two related? Do I initialize the AdomdConnection, then initialize AdomdCommand.Connection to this value? Is this how AdomdCommand knows what open connection to use or where the database in?

I have been using these two sites for reference:

https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.adomdclient.adomdconnection.aspx

https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.adomdclient.adomdcommand.aspx


Solution

  • You can either use CreateCommand() from the connection object, you would then get a command with the Connection property already set to the Connection from which it was created, or create the Command separately (new AdomdCommand()) and set its Connection property.

    Either approach would work.

    As to the actual connection to the database, it does not happen when you create the connection object but rather not until you call the Open() method on the connection object.