See Also

DbConnectionBase Class  | DbConnectionBase Members

 

Language

Visual Basic

C#

Show All

result
The IAsyncResult returned from BeginOpen.
See AlsoRequirementsLanguagesCoreLab.MySqlSend comments on this topic.

EndOpen Method

Ends an asynchronous invocation of the Open method.

[Visual Basic]
Public Sub EndOpen( _    ByVal result As IAsyncResult _ )
[C#]
public void EndOpen(    IAsyncResult result );

Parameters

result
The IAsyncResult returned from BeginOpen.

Remarks

BeginOpen method enables you to open a connection to server without having current thread blocked. In other words, your program can continue execution while the connection is establishing so you do not have to wait for it.

To start opening a connection, you have to call BeginOpen method, which in turn invokes appropriate actions in another thread. Return value of this method must be assigned to IAsyncResult object. After executing this method program flow continues.

When you are ready to use the connection, call EndOpen. If at the moment you call this method the negotiation process has not yet been finished, application stops and waits till the function returns which means that the connection is open.

Refer to "Asynchronous Query Execution" article for detailed information.

Example

This sample shows how to implement asynchronous opening of a connection.

[C#] 

public void AsyncOpen(DbConnectionBase myConnection) 

  IAsyncResult myAsyncResult = myConnection.BeginOpen(null, null); 
  DbCommandBase myCommand = (DbCommandBase)myConnection.CreateCommand(); 
  myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values('100', 'DEVELOPMENT')"; 
  //some operations here 
  myConnection.EndOpen(myAsyncResult); 
  try 
  { 
    myCommand.ExecuteNonQuery(); 
  } 
  finally 
  { 
    myConnection.Close(); 
  } 
}

[Visual Basic] 

Public Sub AsyncOpen(ByVal myConnection As DbConnectionBase)
  Dim myAsyncResult As IAsyncResult = myConnection.BeginOpen(Nothing, Nothing)
  Dim myCommand As DbCommandBase = myConnection.CreateCommand()
  myCommand.CommandText = "INSERT INTO Test.Dept(DeptNo, DName) Values('110', 'QA')"
  ' some operations here
  myConnection.EndOpen(myAsyncResult)
  Try
    myCommand.ExecuteNonQuery()
  Finally
    myConnection.Close()
  End Try
End Sub

 

See Also

DbConnectionBase Class  | DbConnectionBase Members

 

 


© 2002 - 2008 Devart. All Rights Reserved.