views:

139

answers:

4

The following code seased to work.

db.DBUsers.InsertOnSubmit(new DBUser
 {
  AllTheStuff = valuesBeyondYourWildestDreams
 }
);
db.SubmitChanges();

My guess is something changed at the database and the submit is failing because the mapping is off.
As the linq visualiser isn't working for me (bonus points for fixing that) I want to find another way to know what exactly is going wrong and why the submit is failing silently.

Update
I tried using

db.SubmitChanges(ConflictMode.FailOnFirstConflict);

to get an exception, but it seems the submit works. Except that there is no actual new entity in the database.

A: 

For starters I would do:

db.Log = Console.Out;
leppie
Apologies if I'm sounding retarded now, but I'm in a library project, there is no console.
borisCallens
db.Log just wants a TextWriter - you could create a file for logging to.
Graham Clark
You do have a debugger? Then look in the Output window.
leppie
Yes, I do, but nothing relevant is appearing there.
borisCallens
As it seems, nothing is appearing because nothing is sent..
borisCallens
A: 

You could try using SQL Server Profiler if it's an option - start a new trace, connect to the relevant database, then select which events you want to capture.

For basic LINQ debugging, I've found that SP:StmtCompleted (under Stored Procedures) and SQL:StmtCompleted (under TSQL) are enough to show you what SQL LINQ is trying to run.

If you find you're picking up lots of unwanted commands, you can filter these out. For example, I filter out everything coming from the msdb and master databases.

Graham Clark
I only see all kinds of junk, some incoming calls from other queries, but never this query. It seems the submitchanges is not submitting anything..
borisCallens
A: 

This works quite well at debugging linq to sql for us.

Its sends the log information to the output window.

http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11

Hath
A: 

You could also use LINQPad - copy your LINQ code into there, reference the database, and put dumps in to effectively debug the LINQ.

Graham Clark