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, List
1 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