Export (0) Print
Expand All

AdoQueryConnection.Connection property

Gets or sets the connection string used for an AdoQueryConnection object.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

public abstract string Connection { get; set; }

Property value

Type: System.String
The connection string for the data connection represented by the AdoQueryConnection object.

The Connection property of the ADOQueryConnection class provides access to the connection string that is used by the ADO data connection to connect to an ActiveX Data Objects/OLEDB external data source.

NoteNote

The ADOQueryConnection class is limited to work only with Microsoft SQL Server and Microsoft Access databases.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

In the following example, the event handler for a Button control uses the Connection property of the ADOQueryConnection class to update the connection string for the secondary data source named Employees to point to a new server using the value entered in the ServerName field in the main data source. Then the Execute method of the DataConnection class is used to re-query the data connection on the new server.

public void ChangeServerName_Clicked(object sender, ClickedEventArgs e)
{
   // Get the Employees connection from the 
   //DataConnections collection.
   AdoQueryConnection myAdoQueryConnection = 
      (AdoQueryConnection)(this.DataConnections["Employees"]);
   
   // Get the new server name from the ServerName field in 
   // the main data source.
   XPathNavigator myNav = 
      CreateNavigator().SelectSingleNode("/my:myFields/my:ServerName",
      NamespaceManager);
   string newServer = myNav.InnerXml;

   // Build the new connection string.
   string connectionString = 
      "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;";
   connectionString += "Initial Catalog=SalesDB;Data Source=" + 
      newServer;

   // Set the new connection string.
   myAdoQueryConnection.Connection = connectionString;

   // Requery the data source.
   myAdoQueryConnection.Execute();
}
Show:
© 2014 Microsoft