다음을 통해 공유


AdoQueryConnection.Connection 속성

AdoQueryConnection 개체에 사용되는 연결 문자열을 가져오거나 설정합니다.

네임스페이스:  Microsoft.Office.InfoPath
어셈블리:  Microsoft.Office.InfoPath(Microsoft.Office.InfoPath.dll)

구문

‘선언
Public MustOverride Property Connection As String
    Get
    Set
‘사용 방법
Dim instance As AdoQueryConnection
Dim value As String

value = instance.Connection

instance.Connection = value
public abstract string Connection { get; set; }

속성 값

형식: System.String
AdoQueryConnection 개체가 나타내는 데이터 연결의 연결 문자열입니다.

주의

ADOQueryConnection 클래스의 Connection 속성은 ActiveX Data Objects/OLEDB 외부 데이터 원본에 연결하기 위해 ADO 데이터 연결에서 사용하는 연결 문자열에 대한 액세스를 제공합니다.

참고 사항참고 사항

ADOQueryConnection 클래스는 Microsoft SQL Server 및 Microsoft Access 데이터베이스에서만 사용할 수 있도록 제한됩니다.

이 멤버는 현재 열려 있는 양식과 같은 도메인에서 실행하는 양식 또는 도메인 간 권한이 부여된 양식에서만 액세스할 수 있습니다.

이 형식 또는 멤버는 Microsoft InfoPath Filer 또는 웹 브라우저에서 연 양식에서 실행되는 코드에서 액세스할 수 있습니다.

다음 예제에서는 Button 컨트롤에 대한 이벤트 처리기가 ADOQueryConnection 클래스의 Connection 속성을 사용하여 Employees라는 보조 데이터 원본의 연결 문자열을 업데이트함으로써 기본 데이터 원본의 ServerName 필드에 입력된 값을 사용하여 새 서버를 가리킵니다. 그런 다음 DataConnection 클래스의 Execute 메서드를 사용하여 새 서버에서 데이터 연결을 다시 쿼리합니다.

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

참고 항목

참조

AdoQueryConnection 클래스

AdoQueryConnection 멤버

Microsoft.Office.InfoPath 네임스페이스