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)
Syntax
'Declaration
'Usage
Property Value
The connection string for the data connection represented by the AdoQueryConnection object.
Remarks
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.
Note
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 Office InfoPath 2007 or in a Web browser.
Example
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();
}
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
See Also
Reference
AdoQueryConnection Class
AdoQueryConnection Members
Microsoft.Office.InfoPath Namespace