Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
OracleConnection Class

Represents an open connection to a database. This class cannot be inherited.

Namespace:  System.Data.OracleClient
Assembly:  System.Data.OracleClient (in System.Data.OracleClient.dll)
Visual Basic (Declaration)
Public NotInheritable Class OracleConnection _
    Inherits DbConnection _
    Implements ICloneable
Visual Basic (Usage)
Dim instance As OracleConnection
C#
public sealed class OracleConnection : DbConnection, 
    ICloneable
Visual C++
public ref class OracleConnection sealed : public DbConnection, 
    ICloneable
JScript
public final class OracleConnection extends DbConnection implements ICloneable

An OracleConnection object represents a unique connection to an Oracle database. In the case of a client/server database system, it is equivalent to a network connection to the server.

An application that creates an instance of the OracleConnection object can set declarative or imperative security demands that require all direct and indirect callers to have adequate permission to the code. OracleConnection creates security demands by using the OraclePermission object. Users can verify that their code has adequate permissions by using the OraclePermissionAttribute object. Users and administrators can also use the Code Access Security Policy Tool (Caspol.exe) to modify security policy at the machine, user, and enterprise levels. For more information, see Security in the .NET Framework.

NoteNote:

Unlike the Connection object in the other .NET Framework data providers (SQL Server, OLE DB, and ODBC), OracleConnection does not support a ConnectionTimeout property. Setting a connection time-out either as a property or in the connection string has no effect, and the value returned is always zero. OracleConnection also does not support a Database property or a ChangeDatabase method.

If the OracleConnection object goes out of scope, it remains open. Therefore, you should always close OracleConnection objects by calling Close or Dispose, or by using the OracleConnection object within a Using statement. Otherwise, the garbage collection might not free them immediately. Such delays can cause errors if the maximum number of connections is reached while a number of connections are waiting to be deleted by the garbage collector. By contrast, closing the connections by calling Close uses native resources more efficiently, enhancing scalability and improving overall application performance. To ensure that connections are always closed, open the connection inside of a Using block.

NoteNote:

To deploy high-performance applications, you often need to use connection pooling. However, when you use the .NET Framework Data Provider for Oracle, you do not need to enable connection pooling because the provider manages this automatically.

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

Visual Basic
Public Sub InsertRow(ByVal connectionString As String)
    Dim queryString As String = _
      "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"

    Using connection As New OracleConnection(connectionString)
        Dim command As New OracleCommand(queryString)
        command.Connection = connection
        Try
            connection.Open()
            command.ExecuteNonQuery()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Using
End Sub

C#
public void InsertRow(string connectionString)
{
    string queryString = 
        "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        OracleCommand command = new OracleCommand(queryString);
        command.Connection = connection;
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      System.Data.Common..::.DbConnection
        System.Data.OracleClient..::.OracleConnection
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
VB9 with Oracle 11g connection      Nei Bala ... Thomas Lee   |   Edit   |   Show History

ConnectionString ???


How would the connection connectionString for Oracle 11g of the example below.

Public Sub InsertRow(ByVal connectionString As String)
Dim queryString As String = _
"INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"

Using connection As New OracleConnection(connectionString)
Dim command As New OracleCommand(queryString)
command.Connection = connection
Try
connection.Open()
command.ExecuteNonQuery()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using
End Sub

Thanks
Claudinei
nei.silva@vivax.com.br

[tfl - 30 04 09] You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio  : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public     : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

hi      3starsandasun ... Thomas Lee   |   Edit   |   Show History
i would like to ask what are the supported oracle versions supported by system.data.oracleclient?...
thank you..

[tfl - 30 04 09] You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio  : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public     : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker