Conversion failed because the DateTime data value overflowed the type specified for the DateTime value part in the consumer's buffer - oledb

i have a stored procedure in Sybase ASE with date params in it, so when i created a OLE DB Connection and passing the date parameters to the OLE DB Command,And we are mapping to the parameter with OLEDBType.DBTimeStamp type, datetime param type in stored procedure is smalldatetime.
Here is the sample code.
OLEDBConnection con = new OLEDBConnection(connectionstring);
con.open;
OLEDBCommand cmd = new OLEDBCommand(con);
cmd.QueryString = "dbo.job_xb_new"
cmd.QueryType = "Stored Procedure";
cmd.Parameters.Add("#signoff",OLEType.DBTimeStamp);
cmd.Parameters("#signoff").Value = Datetime.now;
cmd.executeNonQuery(); -----------> ERROR HERE
while executing the store-procedure i am receiving the error.
"Conversion failed because the DateTime data value overflowed the type specified for the DateTime value part in the consumer's buffer" ?
Please help!!!

With the only information given there may be a solution to try.
Change the datatype of your input value to the stored proc to a char/varchar
create procedure dbo.myProc
#inDate varchar(20)
AS
BEGIN
..
END
Perform internal conversion from that with CONVERT before passing to your query.
SET #inDate = CONVERT(datetime,#inDate,[style parameter number])
For troubleshooting, just comment out everything in the procedure and SELECT #inDate first to determine what the data coming in from the OLE DB app looks like. You may be in for a surprise there...

Related

failure in serializing optional date type filed to avro regardless of null value or non-null value

We are using avro1.8.2 to serialize data with optional date type field to be published to topic.
record aRecord {
/** Variable: lastUpdate
* lastUpdate indicates the latest date and time the reference asset was updated
*/
union {null, date} lastUpdate = null;
/** Variable: businessDate
* businessDate indicates the business date of the reference asset price
*/
union {null, date} businessDate = null;
}
Ran into the following exception while using the avro tool generated java class to serialize the data:
Error serializing avro message
Caused by: org.apache.avro.AvroRunTimeException: Unknown datum type org.joda.time.LocalDate: 2021-09-17
at org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:772)
at org.apache.avro.specific.SpecificData.getSchemaName(SpecificData.java:302)
at org.apache.avro.generic.GenericData.resolveUnion
Please note that2 this happens regardless of the value is null or non-null (as shown value 2021-09-17 also caused the exception)
We did the following investigation and experiment but could not figure it out why:
Making the date field mandatory, the issue is resolved.
This is because DATE_CONVERSION is added to the corresponding field in the java class generated by avro tool.
If this field is defined as optional and default value is null, DATA_CONVERSION is not added to the java file generated by avro tool.
Using avro 1.9.1 resolved the issue unfortunately we must use avro 1.8.2
We also tried a few other versions of kafka-avro-serializer and spring-boot kafka framework. Nothing works for us.
Other projects that depend on avro1.8.2 seems to be able to handle this and we checked all the places as far as we considered relevant
and all the codes are the same except that somehow they have DATE_CONVERSION in place in the java file
generated by avro tool (although they are defined in advl file exactly the same).
Debuggin into the GenericData.java we found that if DATE_CONVERSION is in place for optional date field, getSchemaName is not called at all.
The getSchemaName basically checks of the type of the object, whether it's an Int, Record, String,...etc.
The date is a logicaltype of joda. Its real type is int as far as we understand
So our questions are:
How to make avro tool enable DATE_CONVERSION for optional "date" type field using avro 1.8.2?
If DATE_CONVERSION is not the key to resolve the issue, what's the best practice to serialize date type field using avro 1.8.2?
and this field could be null (default) or non-null.
Thanks.
SpecificData specificData = SpecificData.get();
specificData.addLogicalTypeConversion(new DateConversion());
DatumWriter<MessageClass> dw = new SpecificDatumWriter<MessageClass>(message.getSchema(), specificData);
DataFileWriter<MessageClass> dfw = new DataFileWriter<MessageClass>(dw);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
dfw.create(message.getSchema(), outputStream);
dfw.append(message);
dfw.close();
ProducerRecord<String, byte[]> record = new ProducerRecord<>(topic, key, outputStream.toByteArray());
return kafkaProducer.send(record, new Callback());
The above code fixed the issue. MessageClass is the java code generated by avro tool.
message is wrapped in specificData which is constructed with new DateConversion()
DATE_CONVERSION is exactly what is needed for optional date field during serialization.
Note that this solution is only needed as a workaround to avro1.8.

Delphi FDQuery Fieldbyname conversion error

I have defined a MySQL database with a table that includes a field of type varchar(128), I call it fieldinquestion. I use a query to access this field, which usually works nicely. However, when I assign a string to the field, I get an error that I don't understand.
try
Self.FDQuery1.FieldByName('fieldinquestion').AsString:='Hello There'; //or something similar.
except
---> error: 'Could not convert variant of type (String) into type (Double)'
aDataType:=Self.FDQuery1.FieldByName(GCssValidationDisplay).DataType; --datatype is ftString
end;
In the try..except clause, this causes an error, but a verification for the datatype shows it is a string!
Any ideas?

How to use a temporary table with dynamic sql?

Im want to use a temporary table with dynamic sql but i have an error saying that the column Column, parameter, or variable #3: Cannot find data type MyTable. Must declare the table variable "#CountriesFound".
Here's my code
ALTER PROCEDURE sqlDynamic #countryId int
AS
CREATE TYPE MyTable AS TABLE ([countries] varchar(50));
DECLARE #statement NVARCHAR(MAX)
DECLARE #CountriesFound AS MyTable
INSERT INTO #CountriesFound(countries)
select Name
FROM CountriesFound
SET #statement =
'SELECT name, CASE WHEN (c.name IN (SELECT countries FROM #CountriesFound)) THEN 1
ELSE 0
END as countryFound FROM Country c WHERE c.countryId = #countryId'
EXECUTE sp_executesql #statement,
N'#countryId int, #CountriesFound MyTable READONLY',
#countryId = #countryId,
#CountriesFound=#CountriesFound;
Any idea how to fix it ?
The error you are getting has nothing to do with dynamic sql. You cannot create a stored procedure that uses a User-Defined DataType (MyTable in your example) in the same procedure that is going to create the TYPE. The TYPE has to already be created before the procedure will even let the code compile.
Consider this simplified code:
CREATE PROCEDURE TypeTest
AS
CREATE TYPE MyTable AS TABLE ([Id] int);
DECLARE #mt AS MyTable;
Just executing this will give the error:
Msg 2715, Level 16, State 3, Procedure TypeTest, Line 1 Column,
parameter, or variable #1: Cannot find data type MyTable. Parameter or
variable '#mt' has an invalid data type.
You need to CREATE the TYPE outside of the procedure code before you try to create the procedure. It doesn't make sense to CREATE a TYPE inside a procedure code, since TYPE objects are permanent on the server until they are dropped anyway, and procedures are usually created to be run multiple times.
It would be nice if the SQL Server gave an error message more to this effect, but SQL Server isn't famous for having the most helpful error messages.

Executing a SQL Server stored procedure from a historian calculation

Using Historian 5.5 and SQL Server 2012.
I have a stored procedure in SQL Server called perfEng_RWtopits and I want to call this procedure from within a calculation tag in Historian Administrator.
The stored procedure returns one float value.
I have the following code so far:
Dim sql
Dim con
Dim cmd
Dim value
sql = "perfEng_RWtopits"
Set con = CreateObject("ADODB.Connection")
con.ConnectionString = "myconnectionstring"
con.Open
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandText = sql
value = cmd.Execute
con.close
Set cmd = Nothing
Set con = Nothing
When I test the calculation I get a value of zero and a quality of bad. If I execute the stored procedure within SQL Server I get 17.123554 (which is correct). Also if I add the following to the end.
Result = value
I get the following error message.
Can anyone help?
You have an error in your vb script. To bad that we can't debug that in Historian Administrator in calcullation tab.
When using a parameterless function you can execute it by writing:
FunctionName
or
FunctionName(), but when you want to pass the result to a variable then you must use () like this value = FunctionName().
You are using function cmd.Execute without () and returning the result to value. Just fix the line
value = cmd.Execute
to
value = cmd.Execute()

How to execute SubSonic3 StoredProcedure with return value

How do I execute a SP and get the return value. The below code always returns null object. The storedprocedure has been tested in the database using the same parameters as in code, but the SubSonic sp always returns null. When executed in the db via sql, it returns the correct values.
This is using SubSonic 3.0.0.3.
myDB db = new myDB();
StoredProcedure sp = db.GetReturnValue(myParameterValue);
sp.Execute();
int? myReturnValue = (int?)sp.Output;
In the above code, sp.Output is always null. When executed in the database, the returned variable is a valid integer (0 or higher) and is never null.
Stored procedure code below:
CREATE PROCEDURE [dbo].[GetReturnValue]
#myVariable varchar(50)
AS
declare #myReturn int
BEGIN
set #myReturn = 5;
return #myReturn;
END
When executing the stored proc in SQL Server, the returned value is '5'.
I copied your sproc and stepped through the SubSonic code and .Output is never set anywhere. A work around would be using an output parameter and referring to it after executing: sproc.OutputValues[0];
Here's a simple way to do it:
In the stored procedure, instead of using RETURN, use SELECT like this:
SELECT ##ROWCOUNT
or
SELECT #TheIntegerIWantToReturn
Then in the code use:
StoredProcName.ExecuteScalar()
This will return the single integer you SELECTED in your stored procedure.
CREATE PROCEDURE [dbo].[GetReturnValue]
#myVariable varchar(50)
#myReturn BIGINT OUTPUT
AS
declare #myReturn int
BEGIN
set #myReturn = 5;
return #myReturn;
END

Resources