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)

'Declaration
PublicMustOverridePropertyConnectionAsStringGetSet
'Usage
DiminstanceAsAdoQueryConnectionDimvalueAsStringvalue = instance.Connection

instance.Connection = value

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 Sub ChangeServerName_Clicked(ByVal sender As Object, _
   ByVal e As ClickedEventArgs)
   ' Get the Employees connection from 
   ' the DataConnections collection.
   Dim myAdoQueryConnection As AdoQueryConnection = _
      DirectCast(Me.DataConnections("Employees"), AdoQueryConnection)

   ' 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.
    myAdoQueryConnection.Execute()
End Sub

Community Additions

Show:
© 2014 Microsoft