views:

91

answers:

2

I am trying to insert a new account in my Acccounts table with linq. I tried using the EntityModel and Linq2Sql. I get no insert into my database nor an exception of any kind.

public static Linq2SQLDataContext dataContext {
        get { return new Linq2SQLDataContext(); }
    }

try {
      //EntityModel
      Accounts acc = Accounts.CreateAccounts(0, Voornaam, Straat, Huisnummer, Stad, Land, 15, EmailReg, Password1);
      Entities.AddToAccounts(acc);
      Entities.SaveChanges();

      //Linq 2 SQL
      Account account = new Account { City = Stad, Country = Land, EmailAddress = EmailReg, Name = Voornaam, Password = Password1, Street = Straat, StreetNr = Huisnummer, StreetNrAdd = Toevoeging, Points = 25 };
      dataContext.Accounts.InsertOnSubmit(account); 

      var conf = dataContext.ChangeConflicts;  // No changeConflicts
      ChangeSet set = dataContext.GetChangeSet(); // 0 inserts, 0 updates, 0 deletes

    try {
        dataContext.SubmitChanges();
    } catch (Exception ex) { }

        } catch (EntityException ex) {          

    }
+4  A: 

You wrap the .SubmitChanges() in a try/catch, but swallow the exception... are you sure no exception is occurring?

BenAlabaster
Positive, In debugmode it doesnt enter the catch.try { dataContext.SubmitChanges();} catch (Exception ex) { string testt = ex.Message.ToString();}
PietjePoeier
A: 

Check your connection string.

David B
Delete connectionstrings and Entity/Linq2Sql models.Rebuild them from a db located in the App_Data folder. Lead to connectionstrings with :Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True""
PietjePoeier