Share via


Connection Representation (Tabular)

The connection object defines the source of the data that populates the tabular model.

Connection Representation

The connection object defines the source of the data that populates the tabular model. It is through the connection object that the model can reach the data from an OLE DB provider; the specification of the connection object follows the rules of OLE DB providers.

Connection in AMO

When using AMO to manage a Tabular Model database, the DataSourceobject in AMO matches one-to-one to the connection logical object in a tabular model.

The following code snippet shows how to create an AMO data source, or Connection object in tabular models.


  //Create an OLEDB connection string
  StringBuilder SqlCnxStr = new StringBuilder();
  SqlCnxStr.Append(String.Format("Data Source={0};" ,SQLServer.Text));
  SqlCnxStr.Append(String.Format("Initial Catalog={0};", SQLDatabase.Text));
  SqlCnxStr.Append(String.Format("Persist Security Info={0};", false));
  SqlCnxStr.Append(String.Format("Integrated Security={0};", "SSPI"));
  SqlCnxStr.Append(String.Format("Provider={0}", "SQLNCLI11"));
  String DatasourceCnxString = SqlCnxStr.ToString();

  //Verify connection string and connectivity
  System.Data.OleDb.OleDbConnection OleDbCnx = new System.Data.OleDb.OleDbConnection(DatasourceCnxString);
  try
  {
      OleDbCnx.Open();
  }
  catch ()
  {
      throw;
  }
  String newDataSourceName = (string.IsNullOrEmpty(DataSourceName.Text) || string.IsNullOrWhiteSpace(DataSourceName.Text)) ? SQLDatabase.Text : DataSourceName.Text;
  AMO.DataSource newDatasource = newDatabase.DataSources.Add(newDataSourceName, newDataSourceName);
  newDatasource.ConnectionString = DatasourceCnxString.Text;
  if (impersonateServiceAccount.Checked)
      newDatasource.ImpersonationInfo = new AMO.ImpersonationInfo(AMO.ImpersonationMode.ImpersonateServiceAccount);
  else
  {
      if (String.IsNullOrEmpty(impersonateAccountUserName.Text))
      {
          MessageBox.Show(String.Format("Account User Name cannot be blank when using 'ImpersonateAccount' mode"), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Information);
          return;
      }
      newDatasource.ImpersonationInfo = new AMO.ImpersonationInfo(AMO.ImpersonationMode.ImpersonateAccount, impersonateAccountUserName.Text, impersonateAccountPassword.Text);
  }
  newDatasource.Update();


AMO2Tabular sample

To have a better understanding on how to use AMO to create and manipulate connection representations see the source code of the AMO to Tabular sample; specifically check in the following source file: Datasource.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.