Question: I am using L2S to access my MSSQL 2008 Express server. I would like to know when the DataContext will open a connection to the DB? and will it close the connection right after it opened it?

For example:

```
var dc = new TestDB();  // connection opened and closed?

dc.SomeTable.InsertOnSubmit(obj);  // connection opened and closed?

foreach(var obj in dc.SomeTable.AsEnumerable())  // connection opened and closed?
{
    ...  // connection opened and closed?
}

dc.SubmitChanges();     // connection opened and closed?

```

Answer: 
LINQ to SQL is good to you: it will open and close the database connection in SubmitChanges().

Also, if you insert more than one record, the inserts will be contained in a single transaction, so either they all succeed or they all fail.

In the case of `foreach(var obj in dc.SomeTable.AsEnumerable())`, a database connection is opened and closed - just once, during which all the records are retrieved.
Don't know about LINQ to SQL internals, but common sense tells that database connections must be opened the least amount of time possible, so it is reasonable to expect that SubmitChanges opens the connection, does its works, and then closes the connection.

Note anyway that you can have access to the DbConnection object used by the DataContext. Maybe if you open the connection by hand, the DataContext will not close it after SubmitChanges finishes (just guessing, never tried it).