简体   繁体   English

发布到服务器后,无法使用Entity Framework和Ajax发布-500内部服务器错误

[英]Working with Entity Framework and ajax post is not working after publishing to a server - 500 internal server error

My project is working fine on my computer running Visual Studio 2010 (SP1) WebServer 我的项目在运行Visual Studio 2010(SP1)WebServer的计算机上运行正常

All of the problems are as usual when publishing to server 发布到服务器时,所有问题都和往常一样

The server is : windows2003 服务器是:windows2003

I don't think it had any prior attempts to run Ef before in other projects 我认为在其他项目中之前没有尝试过运行Ef

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 当我发布表单(使用jQuery / Ajax POST)时,我得到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 Try Catch包装SaveChanges() Try Catch返回500内部服务器错误

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 在服务器上,我的项目只是iis中的一个文件夹

So hierarchy is 所以等级是

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

same with web.config etc web.config相同

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) 我的ef版本是通过NuGet下载的(所以它是V.5)

Both frameworks in my project and on server are set to 4.0 我的项目和服务器上的两个框架都设置为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 ? 我是否必须确定是否有支持ef的.net框架版本(低于4.x ...更新)?

Please help me here its been 3 hours I am struggling trying to solve this issue 请在这里帮助我3个小时以来,我一直在努力解决此问题

update 更新

after changing try Catch to catch Exception insted of DbEntityValidationException 更改后尝试捕获以捕获由DbEntityValidationException异常

the error is 错误是

System.Data.UpdateException: An error occurred while updating the entries. System.Data.UpdateException:更新条目时发生错误。 See the inner exception for details. 有关详细信息,请参见内部异常。 ---> System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2'. ---> System.ArgumentException:使用的SQL Server版本不支持数据类型“ 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, E 在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunB上运行) ,System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,DbAsyncResult结果)处的System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior,runBehavior, System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior行为的String方法)(System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行为)的System.Data.Common.DbCommand.ExecuteReader(CommandBehavior行为)的String方法) .Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator转换器,E ntityConnection connection, Dictionary 2 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 ntityConnection连接,字典2 identifierValues, List 1生成的值(位于System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器))-内部异常堆栈跟踪的结尾--位于System.Data.Mapping System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)在System.Data.Objects.ObjectContext.SaveChanges(SaveOptions选项)处的.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器) c:\\ Inetpub \\ wwwroot \\ sell \\ HtTakalot \\ HtTakalotForm.aspx.cs:第56行的HtTakalot_HtTakalotForm.SendCfrm(Object SentPars)处的ObjectContext.SaveChanges()

Please check that your configuration is valid. 请检查您的配置是否有效。 500 means you asp.net configuration is not valid. 500表示您的asp.net配置无效。 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. 尝试通过命令模式在Microsoft.NET目录aspnet_regiis.exe -i中注册asp.net,并且是否在服务器上安装了ajax工具包或在服务器上复制了工具包dll。

You can check different server code here. 您可以在此处检查其他服务器代码。 http://support.microsoft.com/kb/943891 http://support.microsoft.com/kb/943891

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM