SqlCeConnection Class
Represents an open connection to a SQL Server Compact data source.
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbConnection
System.Data.SqlServerCe.SqlCeConnection
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Syntax
'Declaration
Public NotInheritable Class SqlCeConnection _
Inherits DbConnection
'Usage
Dim instance As SqlCeConnection
public sealed class SqlCeConnection : DbConnection
public ref class SqlCeConnection sealed : public DbConnection
[<SealedAttribute>]
type SqlCeConnection =
class
inherit DbConnection
end
public final class SqlCeConnection extends DbConnection
The SqlCeConnection type exposes the following members.
Constructors
Name | Description | |
---|---|---|
SqlCeConnection() | Initializes a new instance of the SqlCeConnection class. | |
SqlCeConnection(String) | Initializes a new instance of the SqlCeConnection class with the specified connection string. |
Top
Properties
Name | Description | |
---|---|---|
CanRaiseEvents | (inherited from Component) | |
ConnectionString | Gets or sets the string used to open a database. (Overrides DbConnection.ConnectionString.) | |
ConnectionTimeout | Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error. (Overrides DbConnection.ConnectionTimeout.) | |
Container | (inherited from Component) | |
Database | Gets the name of the current database or the database to be used when a connection is open. (Overrides DbConnection.Database.) | |
DatabaseIdentifier | Gets the unique identifier of the current database while synchronizing. | |
DataSource | Gets the file name of the data source. (Overrides DbConnection.DataSource.) | |
DbProviderFactory | (inherited from DbConnection) | |
DesignMode | (inherited from Component) | |
Events | (inherited from Component) | |
ServerVersion | Returns the database version number as a string. (Overrides DbConnection.ServerVersion.) | |
Site | (inherited from Component) | |
State | Gets the current state of the connection. (Overrides DbConnection.State.) |
Top
Methods
Name | Description | |
---|---|---|
BeginDbTransaction | (inherited from DbConnection) | |
BeginTransaction() | Begins a database transaction. | |
BeginTransaction(IsolationLevel) | Begins a database transaction with the current IsolationLevel value. | |
ChangeDatabase | Changes the current database for an open SqlCeConnection. (Overrides DbConnection.ChangeDatabase(String).) | |
Close | Closes the connection to the data source. This is the preferred method of closing any open connection. (Overrides DbConnection.Close().) | |
CreateCommand | Creates and returns a SqlCeCommand object associated with the SqlCeConnection. | |
CreateDbCommand | (inherited from DbConnection) | |
CreateObjRef | (inherited from MarshalByRefObject) | |
Dispose() | Releases all resources used by the current instance of the SqlCeConnection class. | |
Dispose(Boolean) | (inherited from Component) | |
EnlistTransaction(Transaction) | (inherited from DbConnection) | |
EnlistTransaction(Transaction) | Enlists in the specified Transaction. | |
Equals | (inherited from Object) | |
Finalize | (inherited from Component) | |
GetDatabaseInfo | Returns a set of Key Value pairs with information about locale, encryption mode, and case-sensitivity setting of the connected database. | |
GetHashCode | (inherited from Object) | |
GetLifetimeService | (inherited from MarshalByRefObject) | |
GetSchema() | Returns schema information for the data source of this SqlCeConnection. (Overrides DbConnection.GetSchema().) | |
GetSchema(String) | Returns schema information for the data source of this SqlCeConnection using the specified string for the schema name. (Overrides DbConnection.GetSchema(String).) | |
GetSchema(String, array<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, array<String[]).) | |
GetService | (inherited from Component) | |
GetType | (inherited from Object) | |
InitializeLifetimeService | (inherited from MarshalByRefObject) | |
MemberwiseClone() | (inherited from Object) | |
MemberwiseClone(Boolean) | (inherited from MarshalByRefObject) | |
OnStateChange | (inherited from DbConnection) | |
Open | Opens a database connection with the property settings specified by the ConnectionString. (Overrides DbConnection.Open().) | |
ToString | (inherited from Component) |
Top
Events
Name | Description | |
---|---|---|
Disposed | (inherited from Component) | |
FlushFailure | Occurs when the background flush fails. | |
InfoMessage | Occurs when the .NET Compact Framework Data Provider for SQL Server sends a warning or an informational message. | |
StateChange | Occurs when the state of the connection changes. (Overrides DbConnection.StateChange.) |
Top
Explicit Interface Implementations
Name | Description | |
---|---|---|
IDbConnection.BeginTransaction() | (inherited from DbConnection) | |
IDbConnection.BeginTransaction(IsolationLevel) | (inherited from DbConnection) | |
IDbConnection.CreateCommand | (inherited from DbConnection) |
Top
Remarks
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.
Examples
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.
Dim conn As SqlCeConnection = Nothing
Try
conn = New SqlCeConnection("Data Source = MyDatabase.sdf; Password ='<pwd>'")
conn.Open()
Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = "INSERT INTO Customers ([Customer ID], [Company Name]) Values('NWIND', 'Northwind Traders')"
cmd.ExecuteNonQuery()
Finally
conn.Close()
End Try
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();
}
Thread Safety
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.