gpt4 book ai didi

c# - 从 asp.net mvc 5 中的字符串转换日期时间时转换失败

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:13 24 4
gpt4 key购买 nike

我有一个项目使用 asp.net mvc 5,数据库使用 SQL Server 2008,当我在 IIS 服务器 A 中部署应用程序时使用 Windows 7 它正常工作,但是当我在 IIS 服务器 B 中部署时使用 Windows Server 2008 sp 1,应用程序不工作。当我输入值时,错误是

    Server Error in '/SystemPurchase' Application.

Conversion failed when converting datetime from character string.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting datetime from character string.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException (0x80131904): Conversion failed when converting datetime from character string.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +82
System.Data.SqlClient.SqlDataReader.get_MetaData() +135
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6665229
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +6667096
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +577
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +107
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +288
System.Data.SqlClient.SqlCommand.ExecuteReader() +302
SystemPurchase.Models.transaction.insert() in c:\Users\Administrator.USer-PC.000\Documents\Visual Studio 2013\Projects\SystemPurchase\SystemPurchase\Models\transaction.cs:196
SystemPurchase.Controllers.NewEntryController.Index(HttpPostedFileBase filequo1, HttpPostedFileBase filetool1, HttpPostedFileBase filequo2, HttpPostedFileBase filetool2, HttpPostedFileBase filequo3, HttpPostedFileBase filetool3, HttpPostedFileBase filequo4, HttpPostedFileBase filetool4, HttpPostedFileBase filepo, HttpPostedFileBase filetool, FormCollection abc, transaction aa) in c:\Users\Administrator.USer-PC.000\Documents\Visual Studio 2013\Projects\SystemPurchase\SystemPurchase\Controllers\NewEntryController.cs:199
lambda_method(Closure , ControllerBase , Object[] ) +835
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +217
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +12
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +139
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c() +112
System.Web.Mvc.Async.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e() +452
System.Web.Mvc.Async.<>c__DisplayClass30.<BeginInvokeActionMethodWithFilters>b__2f(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +32
System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +231
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

我输入一个模型使用的日期

Datetime.Now.ToString("yyyy/MM/dd H:mm:ss tt")

在服务器 A 中正常运行,没有错误,但在服务器 B 中错误

有什么解决办法吗?

最佳答案

我建议您使用特定的 FormatProvider,如下所示:

Datetime.Now.ToString("yyyy/MM/dd H:mm:ss tt", new CultureInfo("you culture Info"));

Here是一个有用的链接,您可以在其中资助所有可用文化名称的列表。

关于c# - 从 asp.net mvc 5 中的字符串转换日期时间时转换失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24906496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com