Sideway
output.to from Sideway
Draft for Information Only

Content

System.Data.OleDB
 OleDbConnection Class
 Examples
 Remarks
 Constructors
 Properties
 Methods
 Events
 Explicit Interface Implementations
 Applies to
   .NET Core
   .NET Framework
   .NET Platform Extensions
   Xamarin.Mac
 See also
 Examples
 Source/Reference

System.Data.OleDB

The System.Data.OleDb namespace is the.NET Framework Data Provider for OLE DB.

OleDbConnection Class

Namespace:
System.Data.OleDb
Assemblies:
System.Data.dll, System.Data.OleDb.dll

Represents an open connection to a data source.

C#
public sealed class OleDbConnection : System.Data.Common.DbConnection, ICloneable, IDisposable
Inheritance
Object MarshalByRefObject Component OleDbConnection
Implements
IDbConnection ICloneable IDisposable

Examples

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

C#
public void InsertRow(string connectionString, string insertSQL)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        // The insertSQL string contains a SQL statement that
        // inserts a new row in the source table.
        OleDbCommand command = new OleDbCommand(insertSQL);

        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the insert command.
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}

Remarks

An OleDbConnection object represents a unique connection to a data source. With a client/server database system, it is equivalent to a network connection to the server. Depending on the functionality supported by the native OLE DB provider, some methods or properties of an OleDbConnection object may not be available.

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

You can open more than one DataReader on a single OleDbConnection. If the OLE DB provider you use does not support more than one DataReader on a single connection, the provider implicitly opens an additional connection for each.

If the OleDbConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close or Dispose, or by using the OleDbConnection object within a Using statement.

Note

To deploy high-performance applications, you must use connection pooling. When you use the .NET Framework Data Provider for OLE DB, you do not have to enable connection pooling because the provider manages this automatically. For more information about how to use connection pooling with the .NET Framework Data Provider for OLE DB, see OLE DB, ODBC, and Oracle Connection Pooling.

If a fatal OleDbException (for example, a SQL Server severity level of 20 or greater) is generated by the method executing an OleDbCommand, the OleDbConnection might be closed. However, the user can reopen the connection and continue.

An application that creates an instance of the OleDbConnection object can require all direct and indirect callers to have sufficient permission to the code by setting declarative or imperative security demands. OleDbConnection makes security demands using the OleDbPermission object. Users can verify that their code has sufficient permissions by using the OleDbPermissionAttribute object. Users and administrators can also use the Caspol.exe (Code Access Security Policy Tool) to modify security policy at the computer, user, and enterprise levels. For more information, see Code Access Security and ADO.NET.

For more information about handling warning and informational messages from the data server, see Connection Events.

Note

The OleDbConnection object does not support setting or retrieving dynamic properties specific to an OLE DB provider. Only properties that can be passed in the connection string for the OLE DB provider are supported.

Constructors

OleDbConnection()

Initializes a new instance of the OleDbConnection class.

OleDbConnection(String)

Initializes a new instance of the OleDbConnection class with the specified connection string.

Properties

CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
ConnectionString

Gets or sets the string used to open a database.

ConnectionTimeout

Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.

Container

Gets the IContainer that contains the Component.

(Inherited from Component)
Database

Gets the name of the current database or the database to be used after a connection is opened.

DataSource

Gets the server name or file name of the data source.

DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Provider

Gets the name of the OLE DB provider specified in the "Provider= " clause of the connection string.

ServerVersion

Gets a string that contains the version of the server to which the client is connected.

Site

Gets or sets the ISite of the Component.

(Inherited from Component)
State

Gets the current state of the connection.

Methods

BeginTransaction()

Starts a database transaction with the current IsolationLevel value.

BeginTransaction(IsolationLevel)

Starts a database transaction with the specified isolation level.

ChangeDatabase(String)

Changes the current database for an open OleDbConnection.

Close()

Closes the connection to the data source.

CreateCommand()

Creates and returns an OleDbCommand object associated with the OleDbConnection.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
EnlistDistributedTransaction(ITransaction)

Enlists in the specified transaction as a distributed transaction.

EnlistTransaction(Transaction)

Enlists in the specified transaction as a distributed transaction.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetOleDbSchemaTable(Guid, Object[])

Returns schema information from a data source as indicated by a GUID, and after it applies the specified restrictions.

GetSchema()

Returns schema information for the data source of this OleDbConnection.

GetSchema(String)

Returns schema information for the data source of this OleDbConnection using the specified string for the schema name.

GetSchema(String, String[])

Returns schema information for the data source of this OleDbConnection using the specified string for the schema name and the specified string array for the restriction values.

GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Open()

Opens a database connection with the property settings specified by the ConnectionString.

ReleaseObjectPool()

Indicates that the OleDbConnection object pool can be released when the last underlying connection is released.

ResetState()

Updates the State property of the OleDbConnection object.

ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
InfoMessage

Occurs when the provider sends a warning or an informational message.

Explicit Interface Implementations

ICloneable.Clone()

For a description of this member, see Clone().

Applies to

.NET Core

3.0 Preview 7

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

.NET Platform Extensions

3.0 Preview 7

Xamarin.Mac

3.0

See also

 

Examples

Examples of OleDbConnection Class
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
       <title>Sample Page</title>
       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
       <script runat="server" >
           Sub Page_Load()
               Dim xstr As String
               Dim xconn As System.Data.OleDb.OleDbConnection = new System.Data.OleDb.OleDbConnection()
               xconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\test.mdb;User Id=admin;Password=;"
               xconn.Open()
               xstr = xstr + "Database test.mdb connection is opened successfully.<br />"
               xconn.Close()
               xstr = xstr + "Database test.mdb connection is closed successfully.<br />"
               xconn.Dispose()
               xstr = xstr + "Database test.mdb connection is disposed successfully."
               lbl01.Text = xstr
           End Sub
       </script>
    </head>
    <body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
       <% Response . Write ("<h1>This is a Sample Page of OleDbConnection Class</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

Source/Reference


©sideway

ID: 201000027 Last Updated: 10/27/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339new

Travel 7new

Reference 79

Computer

Hardware 251

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 431

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019