Sugerir traducción
 
Otros han sugerido:

progress indicator
No hay más sugerencias.
Evaluar y enviar comentarios
Contraer todo/Expandir todo Contraer todo
Ver contenido:  en paraleloVer contenido: en paralelo
.NET Framework Class Library
IDbConnection Interface

Represents an open connection to a data source, and is implemented by .NET Framework data providers that access relational databases.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)
Visual Basic
Public Interface IDbConnection _
    Inherits IDisposable
C#
public interface IDbConnection : IDisposable
Visual C++
public interface class IDbConnection : IDisposable
F#
type IDbConnection =  
    interface
        interface IDisposable
    end

The IDbConnection type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkConnectionStringGets or sets the string used to open a database.
Public propertySupported by the XNA FrameworkConnectionTimeoutGets the time to wait while trying to establish a connection before terminating the attempt and generating an error.
Public propertySupported by the XNA FrameworkDatabaseGets the name of the current database or the database to be used after a connection is opened.
Public propertySupported by the XNA FrameworkStateGets the current state of the connection.
Top
  NameDescription
Public methodSupported by the XNA FrameworkBeginTransaction()()()Begins a database transaction.
Public methodSupported by the XNA FrameworkBeginTransaction(IsolationLevel)Begins a database transaction with the specified IsolationLevel value.
Public methodSupported by the XNA FrameworkChangeDatabaseChanges the current database for an open Connection object.
Public methodSupported by the XNA FrameworkCloseCloses the connection to the database.
Public methodSupported by the XNA FrameworkCreateCommandCreates and returns a Command object associated with the connection.
Public methodSupported by the XNA FrameworkDisposePerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public methodSupported by the XNA FrameworkOpenOpens a database connection with the settings specified by the ConnectionString property of the provider-specific Connection object.
Top

The IDbConnection interface enables an inheriting class to implement a Connection class, which represents a unique session with a data source (for example, a network connection to a server). For more information about Connection classes, see Connecting to a Data Source (ADO.NET).

An application does not create an instance of the IDbConnection interface directly, but creates an instance of a class that inherits IDbConnection.

Classes that inherit IDbConnection must implement all inherited members, and typically define additional members to add provider-specific functionality. For example, the IDbConnection interface defines the ConnectionTimeout property. In turn, the SqlConnection class inherits this property, and also defines the PacketSize property.

Notes to Implementers

To promote consistency among .NET Framework data providers, name the inheriting class in the form PrvClassname where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. For example, Sql is the prefix of the SqlConnection class in the System.Data.SqlClient namespace.

When you inherit from the IDbConnection interface, you should implement the following constructors:

Item

Description

PrvConnection()

Initializes a new instance of the PrvConnection class.

PrvConnection(string connectionString)

Initializes a new instance of the PrvConnection class when given a string containing the connection string.

The following example creates instances of the derived classes, SqlCommand and SqlConnection. The SqlConnection is opened and set as the Connection for the SqlCommand. 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 a Transact-SQL INSERT statement.

Visual Basic
Private Sub OpenSqlConnection()
    Dim connectionString As String = GetConnectionString()
    Using connection As New SqlConnection(connectionString)
        connection.Open()
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion)
        Console.WriteLine("State: {0}", connection.State)
    End Using
End Sub

Private Function GetConnectionString() As String
    ' To avoid storing the connection string in your code,  
    ' you can retrieve it from a configuration file, using the
    ' System.Configuration.ConfigurationSettings.AppSettings property
    Return "Data Source=(local);Database=AdventureWorks;" _
      & "Integrated Security=SSPI;"
End Function
C#
private static void OpenSqlConnection()
{
    string connectionString = GetConnectionString();
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine("State: {0}", connection.State);
    }
}

static private string GetConnectionString()
{
    // To avoid storing the connection string in your code, 
    // you can retrieve it from a configuration file, using the 
    // System.Configuration.ConfigurationSettings.AppSettings property 
    return "Data Source=(local);Initial Catalog=AdventureWorks;"
        + "Integrated Security=SSPI;";
}

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Biblioteca de clases de .NET Framework
IDbConnection (Interfaz)

Representa una conexión abierta a un origen de datos y la implementan los proveedores de datos de .NET Framework que tienen acceso a bases de datos relacionales.

Espacio de nombres:  System.Data
Ensamblado:  System.Data (en System.Data.dll)
Visual Basic
Public Interface IDbConnection _
    Inherits IDisposable
C#
public interface IDbConnection : IDisposable
Visual C++
public interface class IDbConnection : IDisposable
F#
type IDbConnection =  
    interface
        interface IDisposable
    end

El tipo IDbConnection expone los siguientes miembros.

  NombreDescripción
Propiedad públicaCompatible con XNA FrameworkConnectionStringObtiene o establece la cadena que se utiliza para abrir una base de datos.
Propiedad públicaCompatible con XNA FrameworkConnectionTimeoutObtiene el tiempo de espera para intentar establecer una conexión antes de detenerse y generar un error.
Propiedad públicaCompatible con XNA FrameworkDatabaseObtiene el nombre de la base de datos actual o de la que se va a utilizar una vez que se abre la conexión.
Propiedad públicaCompatible con XNA FrameworkStateObtiene el estado actual de la conexión.
Arriba
  NombreDescripción
Método públicoCompatible con XNA FrameworkBeginTransaction()()()Inicia una transacción de base de datos.
Método públicoCompatible con XNA FrameworkBeginTransaction(IsolationLevel)Inicia una transacción de base de datos con el valor de IsolationLevel especificado.
Método públicoCompatible con XNA FrameworkChangeDatabaseCambia la base de datos actual para un objeto Connection abierto.
Método públicoCompatible con XNA FrameworkCloseCierra la conexión con la base de datos.
Método públicoCompatible con XNA FrameworkCreateCommandCrea y devuelve un objeto Command asociado a una conexión.
Método públicoCompatible con XNA FrameworkDisposeRealiza tareas definidas por la aplicación asociadas a la liberación o al restablecimiento de recursos no administrados. (Se hereda de IDisposable).
Método públicoCompatible con XNA FrameworkOpenAbre una conexión de base de datos con la configuración indicada por la propiedad ConnectionString del objeto Connection específico del proveedor.
Arriba

La interfaz IDbConnection permite que una clase heredada implemente una clase Connection, que representa una sesión única con un origen de datos (por ejemplo, una conexión de red con un servidor). Para obtener más información sobre las clases Connection, vea Conectar con un origen de datos (ADO.NET).

Una aplicación no crea una instancia de la interfaz IDbConnection directamente, sino que la crea de una clase que hereda de IDbConnection.

Las clases que heredan IDbConnection deben implementar todos los miembros heredados y suelen definir miembros adicionales para agregar la funcionalidad específica de proveedor. Por ejemplo, la interfaz IDbConnection define la propiedad ConnectionTimeout. A su vez, la clase SqlConnection hereda esta propiedad y también define la propiedad PacketSize.

Notas para los implementadores

Para potenciar la coherencia entre los proveedores de datos de .NET Framework, asigne a la clase heredada un nombre con el formato PrvClassname, donde Prv es el prefijo uniforme que se asigna a todas las clases de un espacio de nombres de proveedor de datos de .NET Framework específico. Por ejemplo, Sql es el prefijo de la clase SqlConnection en el espacio de nombres System.Data.SqlClient.

Al heredar de la interfaz IDbConnection, se deben implementar los siguientes constructores:

Elemento

Descripción

PrvConnection()

Inicializa una nueva instancia de la clase PrvConnection.

PrvConnection(string connectionString)

Inicializa una nueva instancia de la clase PrvConnection cuando se proporciona una cadena que contiene la cadena de conexión.

En el ejemplo siguiente se crean instancias de las clases derivadas SqlCommand y SqlConnection. Se abre SqlConnection y se establece como Connection para SqlCommand. A continuación, en el ejemplo se llama a ExecuteNonQuery y se cierra la conexión. Para ello, se pasa a ExecuteNonQuery una cadena de conexión y una cadena de consulta que es una instrucción Transact-SQL INSERT.

Visual Basic
Private Sub OpenSqlConnection()
    Dim connectionString As String = GetConnectionString()
    Using connection As New SqlConnection(connectionString)
        connection.Open()
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion)
        Console.WriteLine("State: {0}", connection.State)
    End Using
End Sub

Private Function GetConnectionString() As String
    ' To avoid storing the connection string in your code,  
    ' you can retrieve it from a configuration file, using the
    ' System.Configuration.ConfigurationSettings.AppSettings property
    Return "Data Source=(local);Database=AdventureWorks;" _
      & "Integrated Security=SSPI;"
End Function
C#
private static void OpenSqlConnection()
{
    string connectionString = GetConnectionString();
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine("State: {0}", connection.State);
    }
}

static private string GetConnectionString()
{
    // To avoid storing the connection string in your code, 
    // you can retrieve it from a configuration file, using the 
    // System.Configuration.ConfigurationSettings.AppSettings property 
    return "Data Source=(local);Initial Catalog=AdventureWorks;"
        + "Integrated Security=SSPI;";
}

.NET Framework

Compatible con: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Compatible con: 4, 3.5 SP1

Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2

.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker