0

My project is working fine on my computer running Visual Studio 2010 (SP1) WebServer

All of the problems are as usual when publishing to server

The server is : windows2003

I don't think it had any prior attempts to run Ef before in other projects

So in the beginning I had many errors regarding references though I have managed to overcome those and finally when everything is set in the project and I get to see the page instead of debug errors... and the form is showing, as soon as I submit,

When I post the form (using jQuery/Ajax POST) I get 500 internal server error

Not even knowing what the problem is

Wrapping SaveChanges() with Try Catch returns nothing else but that 500 internal server error

Again, all is good locally but not when published to server

And also the only change from recent projects is this one is using Entity Framework

The using statements

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using HtTakalotModel;
//and this last one was added only to try get more info on the error 
using System.Data.Entity.Validation;

[WebMethod]
public static string SendCfrm(object SentPars)
{
    string newLinw = Environment.NewLine;
    var formValues =(Array) SentPars;
    string cName = "", cPhone = "", cMail = "", cUrgency = "", cComments = "";
    int cLocalSnif = 0;
    string RecordsEfected = "";
    Dictionary<string, string> MainDataDict = new Dictionary<string, string>();
    foreach (Dictionary<string, object> pair in formValues)
    {

        cName = (string)((object[])pair["value"])[0];
        cMail = (string)((object[])pair["value"])[1];
        cPhone = (string)((object[])pair["value"])[2];
        cUrgency = (string)((object[])pair["value"])[3];
        cLocalSnif = ((object[])pair["value"])[4].ToString().ToInt();
        cComments = (string)((object[])pair["value"])[5];
    }
    try
    {
        using (var dbTakalot = new HtTakalotEntities())
        {
            var NewTakala = new tblHtTakalot()
            {
                ClientName = cName,
                ClientPhone = cPhone,
                ClientMail = cMail,
                Urgency = cUrgency,
                LocalSnif = cLocalSnif,
                CreationDate = DateTime.Now,
                TakalaDesc = cComments

            };
            dbTakalot.tblHtTakalot.AddObject(NewTakala);
            RecordsEfected = dbTakalot.SaveChanges().ToString();
        }
    }
    catch (DbEntityValidationException e)
    {
        return e.ToString();
    }
    if (RecordsEfected != "1")
        return "noGo";
    return RecordsEfected;
  }
}

also ... a side note: on my local machine I am running

localhost\projectName\...

On the server my project is just a folder in the iis

So hierarchy is

  inetPub\wwwroot\App_Code 
  inetPub\wwwroot\MyProjectName\App_Code

same with web.config etc

I guess it's common

My main suspicion is that something is not properly configured in the server initially to be able to run Entity Framework

My ef version is downloaded via NuGet (so it is V.5)

Both frameworks in my project and on server are set to 4.0

What could be wrong do I have to make any preinstalation on server ?

Do I have to make sure if there's a .net framework version (sub 4.x... update) to support ef ?

Please help me here its been 3 hours I am struggling trying to solve this issue

update

after changing try Catch to catch Exception insted of DbEntityValidationException

the error is

System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2'. at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary2 identifierValues, List1 generatedValues) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) --- End of inner exception stack trace --- at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at System.Data.Objects.ObjectContext.SaveChanges() at HtTakalot_HtTakalotForm.SendCfrm(Object SentPars) in c:\Inetpub\wwwroot\sell\HtTakalot\HtTakalotForm.aspx.cs:line 56

  • Have you tried to catch `Exception` to see what the error is? Can you debug on the server? – Davin Tryon Jul 23 '13 at 10:20
  • @DavinTryon `return e.ToString();` will not catch and return it ? – Regina Jerusalemsky Jul 23 '13 at 10:23
  • @DavinTryon i need to install Vs on server to debug on server , this is my next step, as the owners of the server did not like working on server making projects he requested to uninstall vs – Regina Jerusalemsky Jul 23 '13 at 10:25
  • It will not catch if the exception is anything other than `DbEntityValidationException`. You should add another catch for `Exception` (just for debugging). – Davin Tryon Jul 23 '13 at 10:42
  • @DavinTryon funny, changed DbEntityValidationException to just Exception Returns no error ,ill chek DB now(: – Regina Jerusalemsky Jul 23 '13 at 10:50
  • There are many questions on SO that address this issue: Here is one: http://stackoverflow.com/questions/10224406/the-version-of-sql-server-in-use-does-not-support-datatype-datetime2 – Davin Tryon Jul 23 '13 at 11:06
  • Look at the stack trace - `The version of SQL Server in use does not support datatype 'datetime2'.`. Also, `RecordsEfected = dbTakalot.SaveChanges().ToString();` looks a bit odd. – MattSull Jul 24 '13 at 22:12

1 Answers1

0

Please check that your configuration is valid. 500 means you asp.net configuration is not valid. Try to register asp.net via command mode in your Microsoft.NET directory aspnet_regiis.exe -i and also did you installed ajax toolkit on server or copied toolkit dll on your server.

You can check different server code here. http://support.microsoft.com/kb/943891

Regards,

Jalpesh Vadgama
  • 13,653
  • 19
  • 72
  • 94