See Also

OracleConnection Members  | Devart.Data.Oracle Namespace  | OracleDataAdapter Class  | OracleCommand Class

Language

Visual Basic

C#

Show All

See AlsoLanguagesDevart.Data.OracleSend comments on this topic.

OracleConnection Class

Devart.Data.Oracle Namespace : OracleConnection Class

Represents an open connection to an Oracle database.

For a list of all members of this type, see OracleConnection members.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DbConnection
            Devart.Common.DbConnectionBase
               Devart.Data.Oracle.OracleConnection

Syntax

[Visual Basic]
Public Class OracleConnection    Inherits DbConnectionBase    Implements IComponentIDbConnectionICloneableIDisposable 
[C#]
public class OracleConnection : DbConnectionBase, IComponentIDbConnectionICloneableIDisposable 

Remarks

A OracleConnection object represents a unique connection to the Oracle database. Use it in conjunction with OracleCommand, OracleDataReader, OracleDataAdapter or other components for convenient interoperation with Oracle database.

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

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

Note that OracleConnection instance is not guaranteed to be thread safe. You should avoid using the same OracleConnection in several threads at the same time. It is recommended to open a new connection per thread and to close it when the work is done. Actually, connections will not be created/disposed every time with the Pooling=true; connection string option - connections will be stored at connection pool. This boosts performance greatly.

A single OracleConnection can be used by many OracleCommand 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.

This class supports cross-form data binding with the InterForm Technology.

Example

The following example creates a OracleCommand and a OracleConnection. The OracleConnection is opened and set as the Connection property. The example then calls ExecuteNonQuery method, and closes the connection. To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.

[C#] 

public void InsertRow(string myConnectionString) 

  // If the connection string is empty, use default. 
  if(myConnectionString == "") 
  { 
    myConnectionString =  
        "User Id=Scott;Password=tiger;Data Source=Ora"; 
  } 
  OracleConnection myConn = new OracleConnection(myConnectionString); 
  string myInsertQuery = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"; 
  OracleCommand myCommand = new OracleCommand(myInsertQuery); 
  myCommand.Connection = myConn; 
  myConn.Open(); 
  try 
  { 
    myCommand.ExecuteNonQuery(); 
  } 
  finally 
  { 
    myConn.Close(); 
  } 

[Visual Basic] 

Public Sub InsertRow(myConnectionString As String)
  ' If the connection string is empty, use default.
  If myConnectionString = "" Then
    myConnectionString = _
        "User Id=Scott;Password=tiger;Data Source=Ora"
  End If
  Dim myConn As New OracleConnection(myConnectionString)
  Dim myInsertQuery As String = "INSERT INTO Test.Dept(DeptNo, DName) Values(50, 'DEVELOPMENT')"
  Dim myCommand As New OracleCommand(myInsertQuery)
  myCommand.Connection = myConn
  myConn.Open()
  Try
    myCommand.ExecuteNonQuery()
  Finally
    myConn.Close()
  End Try
End Sub

See Also

OracleConnection Members  | Devart.Data.Oracle Namespace  | OracleDataAdapter Class  | OracleCommand Class

 

 


© 2002 - 2013 Devart. All Rights Reserved.