Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with displaying results in sqlops - Query failed: Conversion overflows. #275

Closed
eilerth opened this issue Dec 1, 2017 · 13 comments · Fixed by microsoft/sqltoolsservice#1326, microsoft/sqltoolsservice#1352 or #18008

Comments

@eilerth
Copy link

eilerth commented Dec 1, 2017

  • SQL Operations Studio Version: 0.23.6

Steps to Reproduce:
Execute this query: SELECT CAST(80 AS DECIMAL(38, 27))
Rather than returning a result value of 80, I get the error message "Query failed: Conversion overflows."

I can dump that value into a temp table with no problem:
SELECT CAST(80 AS DECIMAL(38, 27)) [a] INTO #a

And then if I try to query the temp table I get the same issue.
If I then cast as FLOAT it returns value just fine:
SELECT CAST([a] AS FLOAT) FROM #a

@kevcunnane
Copy link
Contributor

@saurabh500 this looks at first glance to be a .net core issue. This works fine in SSMS (regular .Net Stack) but fails for us. Stack trace is below - it's reading a decimal into an object buffer using SqlDataReader.GetValues(object[] values);.

Could you help verify this is a dotnet issue rather than something we control, and if so get it tracked in corefx? Stacktrace is below, this is pretty easy to repro.

Exception thrown: 'System.OverflowException' in System.Data.SqlClient.dll: 'Conversion overflows.'
   at System.Data.SqlClient.SqlBuffer.get_Decimal()
   at System.Data.SqlClient.SqlBuffer.get_Value()
   at System.Data.SqlClient.SqlDataReader.GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData)
   at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
   at Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage.StorageDataReader.GetValues(Object[] values) in /Users/me/projects/sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/StorageDataReader.cs:line 116

@saurabh500
Copy link

@kevcunnane I see the same behavior where an exception is thrown on .Net Framework as well. The precision of upto 26 is supported both on .Net core and framework.

using System;
using System.Data.Common;
using System.Data.SqlClient;

namespace SqlClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
            {
                DataSource = "localhost",
                IntegratedSecurity = true
            };
            using (SqlConnection connection = new SqlConnection(builder.ToString()))
            {
                connection.Open();
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT CAST(80 AS DECIMAL(38, 27))"; // 38,26 works
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Object[] values = new Object[reader.FieldCount];

                    int result = reader.GetValues(values);
                    Console.WriteLine(values[0]);
                }
            }

        }
    }
}

anthonydresser pushed a commit that referenced this issue Dec 18, 2017
- Enable basic query execution by adding live connection handling to taskbar buttons
- Remove database dropdown list 
- Add IConnectableEditor, IConnectableEditorParams, and  INewConnectionParams
- Add back IShowQueryResultsEditor
@kburtram kburtram assigned corivera and unassigned saurabh500 Jan 16, 2018
@kburtram kburtram added this to the March Public Preview milestone Jan 23, 2018
@kburtram kburtram removed the Upstream label Jul 16, 2018
@kburtram
Copy link
Member

It looks like SSMS calls DbDataReader::GetSqlValues instead of DbDataReader::GetValues. GetValues throws an System.Overflow exception whereas GetSqlValues correctly returns the result. Unfortunately, simply changing our reader to call GetSqlValues breaks a bunch of other stuff.

Given the impact of issue relative to the size of the change this is something we'll have to pick-up later when there's time to refactor the data reader.

@eilerth
Copy link
Author

eilerth commented Jul 30, 2018 via email

@ranasaria
Copy link
Contributor

ranasaria commented Jul 30, 2018 via email

@philosophicles
Copy link

FWIW this issue on the vscode-mssql project is probably the same thing: microsoft/vscode-mssql#1190

Cross-linking for visibility when people like me search, and in case it helps to bring these different application teams together!

@philosophicles
Copy link

philosophicles commented Mar 29, 2019

Slight advance on the impact of this bug.

This trivial query works as expected:

with cte as (
    select cast(-114.75000 as numeric(38,5)) as RawNum
)
select  RawNum
        --, 1/RawNum
from cte
RawNum
-114.75000

However, running with the 1/RawNum line uncommented:

with cte as (
    select cast(-114.75000 as numeric(38,5)) as RawNum
)
select  RawNum
        , 1/RawNum
from cte

returns

RawNum (No column name)
NULL NULL

With the Query failed: Conversion overflows. error returned as a message.

So the failure in the second column is also affecting the results in the first (and any/all other) columns of the result set. This seems like a possibly-preventable problem to me? Aside from @eilerth 's suggestion, can anything be done to prevent an error with one column affecting rendering of all the others?

@eilerth
Copy link
Author

eilerth commented Mar 30, 2019

In my opinion I'd prefer not to have some of the values still displayed while the overflows are not, I'd rather it be obvious there is a problem with the rendered results so I don't mistakenly use the data that isn't complete.

But I can see value in that suggestion, so thanks for commenting, @philosophicles . Also thanks for linking to the vscode issue for visibility.

@philosophicles
Copy link

I'd rather it be obvious there is a problem with the rendered results so I don't mistakenly use the data

I can also understand that point of view :)

aleklj pushed a commit to aleklj/azuredatastudio that referenced this issue Oct 28, 2019
Very small feature add to make sure that values entered for `TIME` columns are < 24hrs. If the value is >=24hrs when setting the column, an exception will be thrown that the edit/updateCell handler will catch and convert into an error on the JSON RPC side.

* Adding validation of timespan columns

* Fixing a merge conflict
@alanrenmsft alanrenmsft reopened this Dec 15, 2021
@alanrenmsft
Copy link
Contributor

the fix for the issue introduced an issue with money column type and needs to be reverted to unblock the Dec release. reopen the issue and will try to fix it in the next release.

@leandroko
Copy link

Hi!
I used to use vscode-mssql with decimal and thousand separator as comma(,) and dot(.), respectively.
Since version 1.13.0 I am not retrieving data with this characteristic anymore.
Tried to find anything in config, but with no success.
Am I missing any settings? or the changes in 1.13.0 version are not configurable?
Thanks in advance

@alanrenmsft
Copy link
Contributor

@leandroko could you please open a new issue with detailed descriptions?

@leandroko
Copy link

@alanrenmsft sure! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment