SqlDataAdapter.Fill throws SqlException when the BUILTIN Admin lang is Br Engl

  • our c# application uses SqlDataAdapter to fetch data from the DB to present in a report. For some reason the SqlDataAdapter.Fill method is throwing below SqlException when the BUILTIN/Administrators language is British English. When it is English, it is working fine. I debugged my C# code but didn't get a clue why this is happening. Can some one help me overcome this exception?

    {System.Data.SqlClient.SqlException (0x80131904): Error converting data type nvarchar to datetime.

    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

    at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

    at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()

    at System.Data.SqlClient.SqlDataReader.get_MetaData()

    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)

    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)

    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)

    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.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)

    at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

    at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)

    at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

    at ReportViewer.ReportViewer.CreateReportDataSource(ReportRequest reportRequest, String selectString, ReportParameterInfoCollection parameters, DataSet dataSet, SqlConnection connection) in C:\ISSCode\branches\Samra2Freeze\Controls\ReportViewer\ReportViewer.cs:line 367

    ClientConnectionId:fc8c8835-3d91-423e-b467-64c6adf6fecc

    Error Number:8114,State:5,Class:16}

  • error is quite clear

    Error converting data type nvarchar to datetime.

    what you need to do is to look at which field is being converted from a nvarchar/varchar to a date and explicitly convert it on your SQL with the correct convert format so that locale/language settings are ignored.

    same goes to any parameter you may be supplying as a varchar and then converting to a date - this should be converted to a datetime BEFORE the call to sql and passed as a correct datetime variable.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply