Stumped here!

  • Thread starter Thread starter Chevron Boyde
  • Start date Start date
C

Chevron Boyde

Hi All

I have just installed studio 2008 and created a new winforms app.
I have added a sql express db to the project with 1 table called LogEntries
containing 2 columns: LogEntryID (int, auto inc) and LogEntryData (nvarchar
MAX)

I am running some simple LINQ code:
using (LogEntryDataContext db = new LogEntryDataContext())
{
LogEntry log = new LogEntry();
log.LogEntryData = data; //variable passed in

db.LogEntries.InsertOnSubmit(log);
db.SubmitChanges();
}

All runs perfect with no errors but the table never seems to contain any new
rows??

I am stumped as I get no errors? Is there something I am overlooking?

Thanks

Chev
 
Chevron,

Are you doing this in an event handler by chance? If you are, then
there might be an exception being thrown that is being swallowed by the
control firing the event (which is standard winforms behavior).

If you step through the code in the event handler, or place a try/catch
block in the handler, does it catch an exception?
 
Ok I managed to solve the problem. Great waste of 3 hours!

When you add a sql express db to your project to uses AttachDbFilename to
point to the file in you project dir.
When you debug all the relevant files including the DB are copied to the
debug\bin folder. All updates are performed against this db not the db
orginally added. You should set the Copy To Output Directory property of the
file to Copy Never if you want to keep the file in your project.

I prefer adding the connection to the existing DB file and NOT adding the db
to the project.

More resources here:
http://briannoyes.net/PermaLink.aspx?guid=ed45c5c6-24cf-469d-b8cf-aeeef64c4ed1
http://www.msdner.com/dev-archive/16/19-158-169725.shtm

Chev
 
Chevron said:
Ok I managed to solve the problem. Great waste of 3 hours!

When you add a sql express db to your project to uses AttachDbFilename
to point to the file in you project dir.
When you debug all the relevant files including the DB are copied to the
debug\bin folder. All updates are performed against this db not the db
orginally added. You should set the Copy To Output Directory property of
the file to Copy Never if you want to keep the file in your project.

I prefer adding the connection to the existing DB file and NOT adding
the db to the project.

More resources here:
http://briannoyes.net/PermaLink.aspx?guid=ed45c5c6-24cf-469d-b8cf-aeeef64c4ed1

http://www.msdner.com/dev-archive/16/19-158-169725.shtm

Chev

I got bitten by exactly the same scenario yesterday - you're not the
only one!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top