using(var connection = new SqlCeConnection(connectionString)) { // use the connection // ... // end of usage } // connection.Dispose() is called automatically
var connection = new SqlCeConnection(connectionString); try { // use the connection // ... } finally { connection.Dispose(); }In this example, we create a connection outside of a `using` block and manually call `Dispose()` inside a `finally` block. This approach is useful when the connection needs to be passed as a parameter to other methods that may take longer to execute. Package library: `System.Data.SqlServerCe`