I’ve been staring at this until I can’t see straight. I’ve got a console app that i’m using to test the logic out before I convert it to a service. The same code works fine when fired from the web app The student object gets filled fine and it isn’t throwing any errors but when it never saves to the database. any insight on what the heck I’m missing?
my app.config file has the connection string
<connectionStrings>
<add name="DatabaseContext" connectionString="Data Source=|DataDirectory|Development.sdf" providerName="System.Data.SqlServerCe.4.0" />
<add name="DevelopmentEntities" connectionString="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\Development.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
foreach (DataRow dr in dt.Rows)
{
//fill student object and add to list
Student s = new Student();
s.SID = dr[0].ToString();
s.FirstName = dr[1].ToString();
s.LastName = dr[2].ToString();
if (sctType == "TRAD")
{ s.Type = Convert.ToInt32(UniversityGateway.Data.Models.StudentType.Traditional); }
else
{ s.Type = Convert.ToInt32(UniversityGateway.Data.Models.StudentType.AGS); }
s.Email = dr[5].ToString();
s.Address = new Address
{
Street = dr[6].ToString(),
City = dr[9].ToString(),
State = dr[10].ToString(),
Zip = dr[11].ToString(),
};
s.UserActive = "Y";
s.Status = Convert.ToInt32(UniversityGateway.Data.Models.StudentStatus.Pending);
s.Password = "kHPrSps3JnTkmky7PakBZg==Wdc9Qgcz39p+s6+fqk/nUw==";
students.Add(s);
using (var db = new UniversityGateway.Data.DatabaseContext())
{
db.Students.Add(s);
db.SaveChanges();
}
}
Turns out it was saving the object. Just to a different database than what is specified in the connect string. Got another question on SO as to how in the heck to fix that.