Share via


AdoSubmitConnection.Connection Property

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

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Syntax

'Declaration
'Usage

Property Value

The connection string for the data connection.

Remarks

The Connection property of the ADOSubmitConnection object 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.

Important

An ADOSubmitConnection object can only exist when there is a corresponding ADOQueryConnection object, and the data connections represented by both objects share the same set of property values. Changing the value of this property for the ADOSubmitConnection object will also change the value of the same property for the corresponding ADOQueryConnection object.

Note

The ADOSubmitConnection object 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 only from code running in forms opened in Microsoft Office InfoPath 2007.

Example

In the following example, the event handler for a Button control uses the Connection property of the AdoSubmitConnection 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.
   AdoSubmitConnection myAdoSubmitConnection = 
      (AdoSubmitConnection)(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.
   myAdoSubmitConnection.Connection = connectionString;

   // Requery the data source.
   myAdoSubmitConnection.Execute();
}
Public Sub ChangeServerName_Clicked(ByVal sender As Object, _
   ByVal e As ClickedEventArgs)
   ' Get the Employees connection from 
   ' the DataConnections collection.
   Dim myAdoSubmitConnection As AdoSubmitConnection = _
      DirectCast(Me.DataConnections("Employees"), AdoSubmitConnection)

   ' Get the new server name from the ServerName field in 
   ' the main data source.
   Dim myNav As XPathNavigator = _
     CreateNavigator().SelectSingleNode("/my:myFields/my:ServerName", _
      NamespaceManager)
   Dim newServer As String = myNav.InnerXml

   ' Build the new connection string.
   Dim connectionString As String = _
      "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;"
   connectionString = connectionString & _
      "Initial Catalog=SalesDB;Data Source=" & newServer

   ' Requery the data source.
    myAdoSubmitConnection.Execute()
End Sub

See Also

Reference

AdoSubmitConnection Class
AdoSubmitConnection Members
Microsoft.Office.InfoPath Namespace