Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 497
Alexander Prokofyev Avatar asked Apr 15 '09 11:04

Alexander Prokofyev


Video Answer


2 Answers

DataContext.DatabaseExists()

or

DataContext.Connection.Open()
like image 90
leppie Avatar answered Sep 30 '22 07:09

leppie


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?

like image 29
Marc Gravell Avatar answered Sep 30 '22 06:09

Marc Gravell