1

I'm receiving a 500 server error when calling a webservice using ASP.NET and JQuery. I view the response:

Part of the response:

{"Message":"Object reference not set to an instance of an object.","StackTrace":"  

The line that throws it is:

 db.SaveChanges();

On my local computer when I run the site it works, it only throws error on my Windows Server 2012 on AWS. The other thing is that I can't debug it remotely.

The db is initialized and the data that I add to the table is initialized too I've double checked the data that is being entered to the table, even put data manually to make sure, but error still persists.

id variable is retrieved from the function argument, if is not initialized the code doesn't run.

CODE:

 using (siteEntities db = new siteEntities()){
                         {
var c_weekly = (from weekly in db.counters_weekly
    where weekly.product_id == id
    select weekly).SingleOrDefault();

if (c_weekly == null) {
    counters_weekly cw = new counters_weekly();
    cw.count = 0;
    cw.product_id = id;
    cw.year = DateTime.UtcNow.Year;
    cw.week_number = GetIso8601WeekOfYear(DateTime.Now);

    db.counters_weekly.Add(cw);
     db.SaveChanges(); <== THROWS ERROR!!!!

    c_weekly = (from weekly in db.counters_weekly
    where weekly.product_id == id
    select weekly).SingleOrDefault();
}
long weekly_old_count = c_weekly.count;
c_weekly.count = weekly_old_count + Global.DataCounters[id];
db.SaveChanges();
}

Generated by entity Framrwork:

public partial class counters_weekly
{
    public decimal id { get; set; }
    public long product_id { get; set; }
    public int week_number { get; set; }
    public long count { get; set; }
    public int year { get; set; }
}

Any explanation. If there was an easy way to debug online I would have done it. Really need your help on this one. Thanks.

DB: MySQL

Server: Windows Server 2012 EC2 AWS

Using: Latest .NET Connector

Liron Harel
  • 10,819
  • 26
  • 118
  • 217

0 Answers0