I have to create one interface read CSV file and send the request to SQL system to insert data.
In the schema generated for SQL request have createdate field which have datatype as datetime and Nillable as true.
Issue is when I receive the file with empty value for this field getting below error
The string '' is not a valid AllXsd value. at
System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags
kinds)
I tried defult value NULL (In DB if I use insert into using sql query table allows NULL value) But when i set Null value in the request sent by biztalk its not.
"
The adapter failed to transmit message going to send port
"SQLPORTNAME" with URL "SQLSERVERCONNECTIONDETAILS". It will be
retransmitted after the retry interval specified for this Send Port.
Details:"Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException:
The input data for the field/parameter "CreatedDate" is invalid
according to the expected SqlDbType DateTime. --->
System.FormatException: The string '' is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags
kinds) at System.Xml.XmlConvert.ToDateTime(String s,
XmlDateTimeSerializationMode dateTimeOption) at
Microsoft.Adapters.Sql.MetadataHelper.ConvertXmlValueToDotNetObject(String
xmlString, String fieldParameterName, SqlDbType sqlDbType, Int32
maxLength, Int32 precision) --- End of inner exception stack trace---
Server stack trace: at
System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at
System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult
result) at
System.ServiceModel.Channels.ServiceChannel.EndCall(String action,
Object[] outs, IAsyncResult result) at
System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult
result)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type) at
System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult
result) "
Expected result - request should go to SQL without any issue for null/empty values
Change the schema datetime field to a string (nullable) type. This makes parsing easier and less restrictive.
The downside is the loss of automatic conversion of datetime values to the current culture, but I will leave that to you if it's really a downside.
Related
I am migrating a BizTalk 2010 solution to BizTalk 2016. Everything has been largely copied & pasted so no changes there (and the 2010 version works) but when I send a message to a WCF-CUSTOM port - sqlbinding to stored procedures - it stops and logs a type conversion error from string to byte[].
I have tried putting the same message through the 2010 deployment and that works fine but not the 2016. I have tried creating another simple orchestration with the schema generated from the stored procedure and it also produces the error (see below).
The adapter failed to transmit message going to send port "WcfSendPort_SqlAdapterBinding_TypedProcedures_dbo_Custom" with URL "mssql://*****". It will be retransmitted after the retry interval specified for this Send Port. Details:"System.InvalidCastException: Failed to convert parameter value from a String to a Byte[]. ---> System.InvalidCastException: Invalid cast from 'System.String' to 'System.Byte[]'.
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming)
--- End of inner exception stack trace ---
Server stack trace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult result)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult result)
at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)".
The message it should be sending is
Here is the stored proc
CREATE PROCEDURE [dbo].[***]
(
#BatchId BIGINT OUTPUT,
#BatchGuid VARCHAR(50) = NULL,
#Contract VARCHAR(50) = NULL,
#Initiating***Id BIGINT = NULL,
#LinesExpected INT = NULL,
#LinesProcessed INT = NULL,
#SourceSystemMessageId VARCHAR(50) = NULL,
#SourceSystemName VARCHAR(50) = NULL,
#CreatedBy NVARCHAR(255) = NULL,
#RowId TIMESTAMP = 0x00000000000007D9 OUTPUT
)
AS
SET NOCOUNT ON
if #BatchGuid is NULL
set #BatchGuid = ''
if #Contract is NULL
set #Contract = ''
if #Initiating***Id is NULL
set #Initiating***Id = 0
if #LinesExpected is NULL
set #LinesExpected = 0
if #LinesProcessed is NULL
set #LinesProcessed = 0
if #SourceSystemMessageId is NULL
set #SourceSystemMessageId = ''
if #SourceSystemName is NULL
set #SourceSystemName = ''
if #CreatedBy is NULL
set #CreatedBy = ''
INSERT INTO dbo.[***]
(
[BatchGuid],
[Contract],
[Initiating***Id],
[LinesExpected],
[LinesProcessed],
[SourceSystemMessageId],
[SourceSystemName],
[CreatedBy],
[CreatedDate]
)
VALUES
(
#BatchGuid,
#Contract,
#Initiating***Id,
#LinesExpected,
#LinesProcessed,
#SourceSystemMessageId,
#SourceSystemName,
#CreatedBy,
getdate()
)
SELECT #BatchId = Scope_Identity()
SELECT #RowId = RowId FROM [***]
WHERE [BatchId] = #BatchId
SET NOCOUNT OFF
RETURN
GO
Please note the *** are just covering up sensitive information
It turns out the issue was due to the null value in rowId parameter. It would seem that BizTalk 10 handled null values differently.
After taking a crash course for SQLite3, I tried to make a db for my first project:
import sqlite3 as db
conn = db.connect('todo.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE todo(id serial primary key, title text, created
timestamp default now(), done boolean default 'f')")
cursor.execute("INSERT INTO todo (title) VALUES('Learn web.py')")
Unfortunately I receive this error:
OperationalError: near "(": syntax error" at SQLite3
I do not understand what's wrong with the code. Can anyone explain what I am doing wrong?
As shown in the documentation, if the default value is not a simple value, it must be enclosed in parentheses:
CREATE TABLE todo(
...,
created timestamp default (now()),
done boolean default 'f'
);
(And 'f' is not a valid value for a boolean. And now() is not an SQLite function.)
How to use DateTime with SQLite via the SQLProvider type-provider?
SQLite doesn't really have a date and time datatype (see Data types) and stores dates as text. I can pass a date string and query it, and get back a string. So this works, where Date1 in table3 was stored as a string:
query {
for r in table3 do
select (r.Date1)
} |> Seq.toList
val it : string list =
["2016/06/09 0:00:00"; "2016/06/05 0:00:00"; "2016/06/04 0:00:00";
"2016/06/12 0:00:00"; "2016/06/10 0:00:00"; "2016/06/06 0:00:00";
It is also possible to store Date1 as a DateTime, and in another table I have it as such. That is even though SQLite doesn't understand DateTime, I can create a column with the DateTime data type, and I can store a DateTime value in it. I can extract this value in C# (or LinqPad) for example. But when I try to access it via the type provider (the same type provider that let me store the DateTime value), it gives the following error:
System.FormatException: String was not recognized as a valid DateTime.
> at System.DateTimeParse.ParseExactMultiple(String s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.Data.SQLite.SQLiteConvert.ToDateTime(String dateText, SQLiteDateFormats format, DateTimeKind kind, String formatString)
at System.Data.SQLite.SQLite3.GetDateTime(SQLiteStatement stmt, Int32 index)
at System.Data.SQLite.SQLite3.GetValue(SQLiteStatement stmt, SQLiteConnectionFlags flags, Int32 index, SQLiteType typ)
at System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i)
at <StartupCode$FSharp-Data-SqlProvider>.$SqlRuntime.DataContext.FSharp-Data-Sql-Common-ISqlDataContext-ReadEntities#153.GenerateNext(IEnumerable`1& next)
at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source)
at FSharp.Data.Sql.Runtime.QueryImplementation.executeQuery(ISqlDataContext dc, ISqlProvider provider, SqlExp sqlExp, List`1 ti)
at FSharp.Data.Sql.Runtime.QueryImplementation.SqlQueryable`1.System-Collections-Generic-IEnumerable`1-GetEnumerator()
at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
at <StartupCode$FSI_0075>.$FSI_0075.main#()
The difference between the working (type provider) query in table3 and the one with the error in table2 is the data type of the column:
LinqPad correctly sees it as a DateTime in Table2 and this query works there:
var dt2 = new System.DateTime(2016,8,30,0,0,0,DateTimeKind.Local);
Table2
.Where(r => r.Date1 == dt2).Dump();
DateTime type is working as intended with the following versions with SQLProvider 1.0.31 and SQLite 1.0.102:
#if INTERACTIVE
#I #"..\packages\SQLProvider.1.0.31\lib"
#r "FSharp.Data.SqlProvider.dll"
#I #"..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net46"
#r "System.Data.SQLite.dll"
#I #"..\packages\System.Data.SQLite.Linq.1.0.102.0\lib\net46"
#r "System.Data.SQLite.Linq.dll"
#endif
open System
open FSharp.Data.Sql
//open System.Data.SQLite
//open System.Data.SQLite.Linq
[<Literal>]
let connectionString = "Data Source="+ #"C:\tmp\databaseFile.db3"
[<Literal>]
let resolutionPath = __SOURCE_DIRECTORY__ + #"..\..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net46"
type sql = SqlDataProvider<
Common.DatabaseProviderTypes.SQLITE,
connectionString,
ResolutionPath = resolutionPath,
CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>
let ctx = sql.GetDataContext()
let table2 = ctx.Main.Table2 //DateTime
let table3 = ctx.Main.Table3 //Text
I've got an exception while updating a datetime column on SQL Server 2008 Express:
eventinfo.StartDateTime = DateTime.ParseExact(start,
"MM/dd/yyyy hh:mm tt",
CultureInfo.InvariantCulture);
db.Entry(eventinfo).State = EntityState.Modified;
db.SaveChanges();
Exception:
The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.The statement has been terminated.
Any idea how to avoid this exception?
The domain of Sql Server's date/time data types is as follows:
datetime2 (100-nanosecond precision)
1753-01-01T00:00:00.0 — 9999-12-31T23:59:59.9999999.
datetime (millisecond precision...sort of)
1753-01-01T00:00:00.000 — 9999-12-31T23:59:59.997
smalldatetime (1-second precision)
1900-01-01T00:00:00 — 2079-06-06T23:59:59
The CLR DateTime struct has 100-nanosecond precision as well. It is a count of 100-second ticks since its epoch (0001-01-01T00:00:00). Its domain is 0001-01-01T00:00:00 — 9999-12-31T23:59:59.9999999.
You will notice the extended domain of the CLR DateTime as compared to SQL Server's datetime2.
The default value of the CLR's DateTime is its epoch (0001-01-01T00:00:00). Any value prior to 1753-01-01T00:00:00 will throw an out of range exception.
In all likelyhood, your DateTime value is somehow not getting initialized or DateTime.ParseExact() is getting handed junk data, parsing it successfuly and winding up with a date/time prior to 1753-01-01.
I have a table A with an Identity column.
When I insert a row via visualStudio it failed in the SubmitChanges with the following error:
InvalidOperationException: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type
I searched about this in google and I found some discussions about the same issue. one of them is Here.
it says that it's because the procedure returns a null value.
I did as is wrote there. used sql trace, copy the insert command and run it in sql server.
it realy returns null but the row was inserted correctly!!!
the command as it is in the sql trace:
exec sp_executesql N'INSERT INTO [dbo].[MyName_Tbl]([x], [y], [z], [c], [v], [b], [n], [m], [a], [s], [d], [f], [g], [h], [j], [k], [l], [q], [w], [e], [r])
VALUES (#p0, #p1, #p2, #p3, #p4, #p5, #p6, #p7, #p8, #p9, #p10, #p11, #p12, #p13, #p14, #p15, #p16, #p17, #p18, #p19, #p20)
SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]',N'#p0 varchar(8000),#p1 varchar(8000),#p2 nvarchar(4000),#p3 nvarchar(4000),#p4 varchar(8000),#p5 nvarchar(4000),#p6 varchar(8000),#p7 varchar(8000),#p8 nvarchar(4000),#p9 nvarchar(4000),#p10 nvarchar(4000),#p11 nvarchar(4000),#p12 nvarchar(4000),#p13 varchar(8000),#p14 varchar(8000),#p15 nvarchar(4000),#p16 varchar(8000),#p17 nvarchar(4000),#p18 nvarchar(4000),#p19 nvarchar(4000),#p20 decimal(5,2)',#p0='406',#p1='Kabala',#p2=N'01/05/2012 13:47:01',#p3=N'k406/00033',#p4='406/00033',#p5=N'xxx',#p6='127.0.0.1',#p7='10',#p8=N'yyy',#p9=N'hh hh',#p10=N'0527159080',#p11=N'',#p12=N'',#p13='4580',#p14='1',#p15=N'Visa',#p16='0115',#p17=N'10',#p18=N'0',#p19=N'0232323',#p20=0
Can you explain me what's the problem and why in sql it executed correctly and in VS I get an error?
The error you are receiving has nothing to do with an invalid SQL statemt which explains why it works fine when you execute it directly on SQL Server.
The error is being thrown on your app and it's simply because the SQL statement is supposed to return an int containing the value of the last id inserted in the table but instead is returning a NULL value, which makes your program choke since null cannot be assigned to an int unless you declare it as a Nullable<int> (int?)