Verbindungsdarstellung (tabellarisch)
Das Verbindungsobjekt definiert die Quelle der Daten, die das tabellarische Modell auffüllen.
Verbindungsdarstellung
Die Spezifikation für das Verbindungsobjekt folgt den Regeln für OLE DB-Anbieter.
Verbindung in AMO
Wenn eine tabellarische Modelldatenbank mithilfe von AMO verwaltet wird, entspricht das DataSource-Objekt in AMO 1:1 dem logischen Verbindungsobjekt.
Der folgende Codeausschnitt veranschaulicht, wie eine AMO-Datenquelle oder ein Verbindungsobjekt in einem tabellarischen Modell erstellt wird.
//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();
Tabular AMO 2012-Beispiel
Um ein besseres Verständnis für die Verwendung von AMO zur Erstellung und Bearbeitung von Verbindungsdarstellungen zu gewinnen, können Sie den Quellcode im Tabular AMO 2012-Beispiel einsehen. Prüfen Sie insbesondere die Quelldatei: Database.cs. Das Beispiel ist auf Codeplex verfügbar. Beispielcode wird nur zur Verdeutlichung der hier erläuterten logischen Konzepte bereitgestellt und sollte nicht in einer Produktionsumgebung verwendet werden.