Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Closes the connection to the data source. This is the preferred method of closing any open connection.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Syntax
'Declaration
Public Overrides Sub Close
'Usage
Dim instance As SqlCeConnection
instance.Close()
public override void Close()
public:
virtual void Close() override
abstract Close : unit -> unit
override Close : unit -> unit
public override function Close()
Implements
Remarks
The Close method rolls back any pending transactions and then releases the connection. If Close is called while handling a StateChange event, no additional StateChange events are fired.
An application can call Close more than one time. No exception is generated.
Examples
The following example creates a SqlCeConnection, opens it, executes a query, and then 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();
}