Compartilhar via


AdoQueryConnection.Connection Propriedade

Definição

Obtém ou define o cadeia de conexão usado para um AdoQueryConnection objeto.

public:
 abstract property System::String ^ Connection { System::String ^ get(); void set(System::String ^ value); };
public abstract string Connection { get; set; }
member this.Connection : string with get, set
Public MustOverride Property Connection As String

Valor da propriedade

O cadeia de conexão para a conexão de dados representada pelo AdoQueryConnection objeto.

Exemplos

No exemplo a seguir, o manipulador de eventos de um controle Button usa a propriedade Connection da classe ADOQueryConnection para atualizar o cadeia de conexão da fonte de dados secundária chamada Employees para apontar para um novo servidor usando o valor inserido no campo ServerName na fonte de dados main. Em seguida, o Execute()DataConnection método da classe é usado para consultar novamente a conexão de dados no novo servidor.

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

Comentários

A propriedade Connection da classe ADOQueryConnection fornece acesso ao cadeia de conexão que é usado pela conexão de dados ADO para se conectar a uma fonte de dados externa do ActiveX Data Objects/OLEDB.

Observação: a classe ADOQueryConnection está limitada a funcionar apenas com bancos de dados microsoft SQL Server e Microsoft Access.

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.

Aplica-se a