Share via


SqlCeCommand.Connection Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets or sets the SqlCeConnection used by this instance of the SqlCeCommand.

  [Visual Basic]
  Public Property Connection As SqlCeConnection
[C#]
public SqlCeConnection Connection {get; set;}
[C++]
public: __property SqlCeConnection* get_Connection();
public: __property void set_Connection(SqlCeConnection*);
[JScript]
public function get Connection() : SqlCeConnection;
public function set Connection(SqlCeConnection);

Property Value

The connection to a data source. The default value is a null reference (Nothing in Visual Basic).

Exceptions

Exception Type Condition
InvalidOperationException The Connection property was changed while a transaction was in progress.

Remarks

Although SQL Server CE only supports one connection at a time, multiple commands can share the same connection. Thus, it is possible to have multiple instances of SqlCeDataReader open on the same connection. This behavior differs from that of System.Data.SqlClient.

You cannot set the Connection, CommandType, and CommandText properties if the current connection is performing an Execute or Fetch operation.

If you set Connection while a transaction is in progress and the Transaction property is not null, an InvalidOperationException is generated. If the Transaction property is not null and the transaction has already been committed or rolled back, Transaction is set to null.

Requirements

Platforms: .NET Compact Framework

.NET Framework Security:

See Also

SqlCeCommand Class | SqlCeCommand Members | System.Data.SqlServerCe Namespace | CommandText | CommandTimeout | CommandType

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Send comments on this topic.

© Microsoft Corporation. All rights reserved.