Alexander Prokofyev
Alexander Prokofyev

Reputation: 34515

How to check for LINQ to SQL connection error

How to check if Linq.DataContext object is filled with data and no connection error has appeared?

Thanks.

Upvotes: 9

Views: 8650

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1062820

What specific scenario are you trying to guard against?

A DataContext is not the same as a DataSet - it isn't (necessarily) a container of data (identity management / change tracking aside) - it is a source of data.

In general, it won't give you an object (from a query) if an error occurs - it'll throw an exception. So if you have been given an instance by LINQ-to-SQL, it should have something in it.

Are you seeing a specific problem that you want to avoid?

Upvotes: 2

leppie
leppie

Reputation: 117240

DataContext.DatabaseExists()

or

DataContext.Connection.Open()

Upvotes: 20

Related Questions