dotConnect Universal Documentation
Devart.Data.Universal Namespace / UniConnection Class
Members Example

In This Topic
    UniConnection Class
    In This Topic
    Represents an open connection to a server.
    Syntax
    Remarks

    A UniConnection object represents a unique connection to the server. Use it in conjunction with UniCommand, UniDataReader, UniDataAdapter or other components for convenient interoperation with database.

    When you create an instance of UniConnection, all properties are set to their initial values. For a list of these values, see the UniConnection Constructor constructor.

    If the UniConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close.

    A single UniConnection can be used by many UniCommand objects on the assumption that all operations will be done consecutively. In other words, you can not execute a SQL statement while an asynchronous operation is in progress.

    Example
    The following example creates a UniCommand and a UniConnection. The UniConnection is opened and set as the Connection property. The example then calls Devart.Common.DbCommand.ExecuteNonQuery method, and closes the connection. To accomplish this, the Devart.Common.DbCommand.ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.
    public void InsertRow(string myConnectionString)
    {
      // If the connection string is empty, use default.
      if(myConnectionString == "")
      {
        myConnectionString = "Provider=SQL Server;Data Source=SERVER;Initial Catalog=Northwind;User ID=sa";
      }
      UniConnection myConn = new UniConnection(myConnectionString);
      string myInsertQuery = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')";
      UniCommand myCommand = new UniCommand(myInsertQuery);
      myCommand.Connection = myConn;
      myConn.Open();
      try
      {
        myCommand.ExecuteNonQuery();
      }
      finally
      {
        myConn.Close();
      }
    }
    Public Sub InsertRow(myConnectionString As String)
      ' If the connection string is empty, use default.
      If myConnectionString = "" Then
        myConnectionString = "Provider=SQL Server;Data Source=SERVER;Initial Catalog=Northwind;User ID=sa"
      End If
      Dim myConn As New UniConnection(myConnectionString)
      Dim myInsertQuery As String = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
      Dim myCommand As New UniCommand(myInsertQuery)
      myCommand.Connection = myConn
      myConn.Open()
      Try
        myCommand.ExecuteNonQuery()
      Finally
        myConn.Close()
      End Try
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             System.Data.Common.DbConnection
                Devart.Common.DbConnectionBase
                   Devart.Data.Universal.UniConnection

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also