dotConnect for SQL Server Documentation
Devart.Data.SqlServer Namespace / SqlConnection Class / Clone Method
Example

On this page
    Clone Method (SqlConnection)
    On this page
    Creates a new object that is a copy of the current instance.
    Syntax
    'Declaration
     
    Public Function Clone() As SqlConnection
    public SqlConnection Clone()

    Return Value

    A new SqlConnection object.
    Remarks

    Creates a new SqlConnection object with the properties that have the same values as those of the original object. However, changing properties of the new object has no influence on the values of the same properties of the original object.

    Note that state of the new instance is always Closed, regardless of the state of original instance.

    Example
    This example shows how to clone a SqlConnection. To make sure all the properties are inherited, one of them (UserId) is written to the console.
    public void CloneAConnection()
    {
      SqlConnection sqlConnection = new SqlConnection(
          "User Id=sa;Server=localhost;Initial Catalog=Test;");
      SqlConnection sqlConnection2 = (SqlConnection)sqlConnection.Clone();
      Console.WriteLine(sqlConnection2.UserId);
    }
    Public Sub CloneAConnection()
      Dim sqlConnection As New SqlConnection( _
          "User Id=sa;Server=localhost;Initial Catalog=Test;")
      Dim sqlConnection2 As SqlConnection = CType(sqlConnection.Clone(), SqlConnection)
      Console.WriteLine(sqlConnection2.UserId)
    End Sub
    See Also