Hello,
I am having trouble with an MSSQL create data item method. The data is of type string/nvarchar, but the insert-command in the log appears to try inserting it as datetime, which is wrong.
From data/DB.json model :
"MdlmExternalUserOrder": {
"x-table": "dbo.MDLM_ExternalUserOrder",
"resource": "MdlmExternalUserOrders",
"required": [
"FirstName",
"LastName",
"JobTitle",
"InvoiceCompanyID",
"ExternalCompanyID",
"LocationID",
"MobilePhoneNumberPrefix",
"MobilePhoneNumber",
"ExternalEmail",
"StartDate",
"ServiceUserTypeID",
"OrderedByUserUPN",
"OrderDate"
],
"properties": {
...
"MobilePhoneNumberPrefix": {
"x-nullable": false,
"type": "string",
"dbType": "nvarchar",
"length": 50
},
...
}
The string in question is "+46" or "+47".
Error on insert, note how parameter @p12 (MobilePhoneNumberPrefix) is DbType=DateTime, when it should have been nvarchar:
dotnet: fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (4ms) [Parameters=[@p0='?' (DbType = Date), @p1='?' (DbType = Int32), @p2='?' (Size = 4000), @p3='?' (Size = 4000), @p4='?' (Size = 4000), @p5='?' (DbType = Int32), @p6='?' (Size = 4000), @p7='?' (Size = 4000), @p8='?' (DbType = Int32), @p9='?' (DbType = Int32), @p10='?' (Size = 4000), @p11='?' (Size = 4000), @p12='?' (DbType = DateTime), @p13='?' (Size = 4000), @p14='?' (DbType = Boolean), @p15='?' (DbType = Boolean), @p16='?' (DbType = Int32), @p17='?' (DbType = Date), @p18='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
SET NOCOUNT ON;
INSERT INTO [dbo].[MDLM_ExternalUserOrder] ([EndDate], [ExternalCompanyID], [ExternalCompanyName], [ExternalEmail], [FirstName], [InvoiceCompanyID], [JobTitle], [LastName], [LocationID], [ManagerUserID], [MobilePhoneNumber], [MobilePhoneNumberPrefix], [OrderDate], [OrderedByUserUPN], [ServiceNetwork], [ServicePrint], [ServiceUserTypeID], [StartDate], [UserOrderID])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18);
SELECT [OrderID]
FROM [dbo].[MDLM_ExternalUserOrder]
WHERE @@ROWCOUNT = 1 AND [OrderID] = scope_identity();
dotnet: fail: Microsoft.EntityFrameworkCore.Update[10000]
An exception occurred in the database while saving changes for context type 'Brukeradministrasjonsportal.Data.MdlmIdrettsKontorDbContext'.
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
---> System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value)
at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value)
at System.Data.SqlTypes.SqlDateTime..ctor(DateTime value)
at Microsoft.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb)
at Microsoft.Data.SqlClient.TdsParser.WriteUnterminatedValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj, Int32 paramSize, Boolean isDataFeed)
at Microsoft.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj, Int32 paramSize, Boolean isDataFeed)
at Microsoft.Data.SqlClient.TdsParser.TDSExecuteRPCAddParameter(TdsParserStateObject stateObj, SqlParameter param, MetaType mt, Byte options)
at Microsoft.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)