接続オブジェクトは、表形式モデルを設定するデータのソースを定義します。
接続表現
接続オブジェクトの仕様は、OLE DB プロバイダーの規則に従います。
AMO での接続
AMO を使用して表形式モデル データベースを管理する場合、AMO の DataSource オブジェクトは、接続論理オブジェクトと 1 対 1 で一致します。
次のコード スニペットは、表形式モデルで AMO データ ソースまたは Connection オブジェクトを作成する方法を示しています。
//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();
表形式 AMO 2012 サンプル
AMO を使用して接続表現を作成および操作する方法について理解を深めるために、表形式 AMO 2012 サンプルのソース コードを参照してください。具体的には、次のソース ファイルをチェックインします: Database.cs。 サンプルは Codeplex で入手できます。 サンプル コードは、ここで説明する論理的な概念のサポートとしてのみ提供されており、運用環境では使用しないでください。