Export (0) Print
Expand All

SqlCeConnection Class

Represents an open connection to a SQL Server Compact data source.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

public sealed class SqlCeConnection : DbConnection

The SqlCeConnection type exposes the following members.

  NameDescription
Public methodSqlCeConnection()Initializes a new instance of the SqlCeConnection class.
Public methodSqlCeConnection(String)Initializes a new instance of the SqlCeConnection class with the specified connection string.
Top

  NameDescription
Protected propertyCanRaiseEvents (inherited from Component)
Public propertyConnectionStringGets or sets the string used to open a database. (Overrides DbConnection.ConnectionString.)
Public propertyConnectionTimeoutGets the time to wait while trying to establish a connection before terminating the attempt and generating an error. (Overrides DbConnection.ConnectionTimeout.)
Public propertyContainer (inherited from Component)
Public propertyDatabaseGets the name of the current database or the database to be used when a connection is open. (Overrides DbConnection.Database.)
Public propertyDatabaseIdentifierGets the unique identifier of the current database while synchronizing.
Public propertyDataSourceGets the file name of the data source. (Overrides DbConnection.DataSource.)
Protected propertyDbProviderFactory (inherited from DbConnection)
Protected propertyDesignMode (inherited from Component)
Protected propertyEvents (inherited from Component)
Public propertyServerVersionReturns the database version number as a string. (Overrides DbConnection.ServerVersion.)
Public propertySite (inherited from Component)
Public propertyStateGets the current state of the connection. (Overrides DbConnection.State.)
Top

  NameDescription
Protected methodBeginDbTransaction (inherited from DbConnection)
Public methodBeginTransaction()Begins a database transaction.
Public methodBeginTransaction(IsolationLevel)Begins a database transaction with the current IsolationLevel value.
Public methodChangeDatabaseChanges the current database for an open SqlCeConnection. (Overrides DbConnection.ChangeDatabase(String).)
Public methodCloseCloses the connection to the data source. This is the preferred method of closing any open connection. (Overrides DbConnection.Close().)
Public methodCreateCommandCreates and returns a SqlCeCommand object associated with the SqlCeConnection.
Protected methodCreateDbCommand (inherited from DbConnection)
Public methodCreateObjRef (inherited from MarshalByRefObject)
Public methodDispose()Releases all resources used by the current instance of the SqlCeConnection class.
Protected methodDispose(Boolean) (inherited from Component)
Public methodEnlistTransaction(Transaction) (inherited from DbConnection)
Public methodEnlistTransaction(Transaction)Enlists in the specified Transaction.
Public methodEquals (inherited from Object)
Protected methodFinalize (inherited from Component)
Public methodGetDatabaseInfoReturns a set of Key Value pairs with information about locale, encryption mode, and case-sensitivity setting of the connected database.
Public methodGetHashCode (inherited from Object)
Public methodGetLifetimeService (inherited from MarshalByRefObject)
Public methodGetSchema()Returns schema information for the data source of this SqlCeConnection. (Overrides DbConnection.GetSchema().)
Public methodGetSchema(String)Returns schema information for the data source of this SqlCeConnection using the specified string for the schema name. (Overrides DbConnection.GetSchema(String).)
Public methodGetSchema(String, String[])Returns schema information for the data source of this SqlCeConnection using the specified string for the schema name and the specified string array for the restriction values. (Overrides DbConnection.GetSchema(String, String[]).)
Protected methodGetService (inherited from Component)
Public methodGetType (inherited from Object)
Public methodInitializeLifetimeService (inherited from MarshalByRefObject)
Protected methodMemberwiseClone() (inherited from Object)
Protected methodMemberwiseClone(Boolean) (inherited from MarshalByRefObject)
Protected methodOnStateChange (inherited from DbConnection)
Public methodOpenOpens a database connection with the property settings specified by the ConnectionString. (Overrides DbConnection.Open().)
Public methodToString (inherited from Component)
Top

  NameDescription
Public eventDisposed (inherited from Component)
Public eventFlushFailureOccurs when the background flush fails.
Public eventInfoMessageOccurs when the .NET Compact Framework Data Provider for SQL Server sends a warning or an informational message.
Public eventStateChangeOccurs when the state of the connection changes. (Overrides DbConnection.StateChange.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDbConnection.BeginTransaction() (inherited from DbConnection)
Explicit interface implemetationPrivate methodIDbConnection.BeginTransaction(IsolationLevel) (inherited from DbConnection)
Explicit interface implemetationPrivate methodIDbConnection.CreateCommand (inherited from DbConnection)
Top

A SqlCeConnection object represents a unique connection to a data source. When you create an instance of SqlCeConnection, all properties are set to their initial values. For a list of these values, see the SqlCeConnection constructor.

If the SqlCeConnection goes out of scope, it is not closed. You must explicitly close the connection by calling Close or Dispose.

SQL Server Compact supports multiple simultaneous connections as well as multiple commands that share the same connection. This means that you can have multiple instances of SqlCeDataReader open on the same connection. This behavior differs from that of System.Data.SqlClient.

If a fatal SqlCeException is generated by the method executing a SqlCeCommand, the SqlCeConnection may be closed. You can reopen the connection and continue.

The following example creates a SqlCeCommand and a SqlCeConnection. The SqlCeConnection is opened and set as the Connection for the SqlCeCommand. The example then calls ExecuteNonQuery and closes the connection.

SqlCeConnection conn = null;

try
{
    conn = new SqlCeConnection("Data Source = MyDatabase.sdf; Password ='<pwd>'");
    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();
    cmd.CommandText = "INSERT INTO Customers ([Customer ID], [Company Name]) Values('NWIND', 'Northwind Traders')";

    cmd.ExecuteNonQuery();
}
finally
{
    conn.Close();
}


Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft