2

I am using Linq-To-SQL to perform inserts into a table that has the following definition (omitting some superfluous fields):

ID int not null
SourceName varchar(100)
Version int not null
TransactionID int not null
Xml nvarchar(max)

ID, SourceName, Version and TransactionID form the primary key for the table. There are no foreign keys or constraints.

I create a DataContext for my database and then create a new record. When I call SubmitChanges on my DataContext a StackOverflowException is thrown.

using (var ctx = new MyDataContext(connectionString))
{
    var row = new MyTable
    {
        ID = 1
        , SourceName = "foo"
        , Version = 1
        , TransactionID = 0 //this is the weird part - see below
        , Xml = "some xml string"
    }

    ctx.MyTable.InsertOnSubmit(row);
    ctx.SubmitChanges();
}

However, after lots of value substituting and trial and error the StackOverflowException does not get thrown if I change TransactionID to 1 (I initially assumed the Xml field was somehow overflowing).

I was using 0 just for the scenarios where for a transaction id could not be identified some reason.

I obviously googled this but the only related issue I found was caused by a foreign key relationship.

Anyone have any idea why this is happening? I have a work around but am curious what could be the cause.

I am using .Net 3.5 and SQL Server 2005.

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50

0 Answers0