Skip to content

UDT parameters are limited to 64K #329

Closed

Description

@ajcvickers

This is an issue because serialized spatial types can easily be bigger than this. See dotnet/efcore#18813.

@Wraith2 pointed to the place in the code where this limitation exists:

//it may be legitimate, but we dont support it yet
if (size < 0 || (size >= ushort.MaxValue && maxsize != -1))
throw new IndexOutOfRangeException();

/cc @bricelam

Activity

  1. cheenamalhotra commented on Nov 27, 2019

    @cheenamalhotra
    Member

    It seems that the driver can support larger data size for UDT Types (upto 2 GB, i.e. max LOB size, identified by 0x7FFFFFFF token with length as -1, identified by 0xFFFF token), as introduced in TDS 7.3, but the support was not added to the driver.

    Quoting MS TDS:

    The value 0xFFFF signifies the maximum LOB size indicating a UDT with a maximum size greater than 8000 bytes (also referred to as a Large UDT; introduced in TDS 7.3).

    This applies to both .NET Framework and .NET Core.
    Issue would be categorized as an enhancement.

  2. Wraith2 commented on Nov 27, 2019

    @Wraith2
    Contributor

    That shouldn't be too hard to fix. If i get time i'll have a go. I'd also like to change the exception type that it throws and give a sensible message to the user explaining why they're getting the error. A default IndexOutOfRange exception makes it look like an internal problem (fooled me when i was investigating) rather than something the user can address.

  3. Wraith2 commented on Nov 29, 2019

    @Wraith2
    Contributor

    How do you get the connection tds protocol version?There's a major+minor version on the session but that doesn't seem to get used. There's also _isYukon _isKatmai _isDenali on the parser but I'm not sure how they map to protocol versions.

  4. cheenamalhotra commented on Nov 29, 2019

    @cheenamalhotra
    Member

    @Wraith2

    TDSParser when parses tokens calls this method for LOGINACK token:

    internal void OnLoginAck(SqlLoginAck rec)
    {
    _loginAck = rec;
    if (_recoverySessionData != null)
    {
    if (_recoverySessionData._tdsVersion != rec.tdsVersion)
    {
    throw SQL.CR_TDSVersionNotPreserved(this);
    }
    }
    if (_currentSessionData != null)
    {
    _currentSessionData._tdsVersion = rec.tdsVersion;
    }
    }

  5. aprognimak commented on Dec 2, 2019

    @aprognimak

    Ehm, guys, any workaround (no matter how ugly)?
    This used to work in 2.2 and it really is not an enhancement but a breaking bug

  6. Wraith2 commented on Dec 2, 2019

    @Wraith2
    Contributor

    It didn't work in 2.2. It's been this way since the inception of the feature, the only thing that can have changed is the amount of data you feed it. I'm working my way through the fix but I've got a few things going on at the minute so it's a bit slow.

  7. ajcvickers commented on Dec 2, 2019

    @ajcvickers
    Author

    @bricelam Is it possible that EF Core didn't hit this in 2.2 because it was using a different mechanism that didn't hit this exact code path? (I don't remember exactly what we changed here.)

  8. aprognimak commented on Dec 2, 2019

    @aprognimak

    It didn't work in 2.2. It's been this way since the inception of the feature, the only thing that can have changed is the amount of data you feed it. I'm working my way through the fix but I've got a few things going on at the minute so it's a bit slow.

    Well it did. Just triple hours ago I was on 2.2 using the olden NetTopologySuite types, those IGeometry and all that stuff. However saving changes to the context when using spatial data even when there were no changes took enormous time (minutes for 1k+ shapes, unchanged) so I moved to 3.0.1 and it just stopped working.
    Now I can't reseed my db with us state county borders because even with the least accuracy some of those don't fit into 64k parameter value. 2.2 most likely used quite different approach when dealing with spatial data given it was just introduced then.

    Trying postgres now.

  9. capesean commented on Dec 3, 2019

    @capesean

    Ehm, guys, any workaround (no matter how ugly)?
    This used to work in 2.2 and it really is not an enhancement but a breaking bug

    I’m using ExecuteSqlRaw with geometry::STGeomFromText('{geometry.ToString()}' as a temporary fix.

  10. bricelam commented on Dec 3, 2019

    @bricelam

    EF Core didn't hit this in 2.2 because it was using a different mechanism

    Correct. We were using SqlBytes parameters (not UDTs) in 2.2. We switched to UDTs in 3.0 to fix dotnet/efcore#14595

  11. ajcvickers commented on Dec 3, 2019

    @ajcvickers
    Author

    @cheenamalhotra I think this raises the priority of getting this changed, since without it customers using spatial with EF Core will be running into blocking issues. Hopefully @Wraith2 will come up with a fix, but if not can we raise the priority of getting this in?

  12. Wraith2 commented on Dec 4, 2019

    @Wraith2
    Contributor

    Prospective fix is posted #340

  13. cheenamalhotra commented on Dec 5, 2019

    @cheenamalhotra
    Member

    Thanks for the PR @Wraith2

    Is there a special reason to increase size limit to int.MaxValue? I'm wondering if it would bring back the same support as sending data as SqlBytes previously with .NET Core 2.2.

    The size we're looking at is 2 GB LOBs that driver needs to support with Large UDTs.

  14. cheenamalhotra commented on Dec 5, 2019

    @cheenamalhotra
    Member

    Ok, I see the driver does support Large UDTs, it was probably not hitting the right code path when working with large data. I'll continue to review PR and post comments there, just want to make sure the metadata information is available as per specs.

  15. Wraith2 commented on Dec 5, 2019

    @Wraith2
    Contributor

    It can already receive large UDTs but the check in sending them was hardcoded to short.MaxValue which as you pointed out earlier in this discussion was only for 2005. I just made the check version aware.

    Since sending the UDT doesn't require you to send the size field for the UDT description this check could be omitted entirely but if a user did go over the limit they would get an SqlException back from the server after having had to wait for transferring>2Gib and it wouldn't be a very friendly message.

  16. loth0 commented on Dec 12, 2019

    @loth0

    Any hint on when this fix will show up in ef core? This is what's blocking us from upgrading to ef core 3

  17. Wraith2 commented on Dec 12, 2019

    @Wraith2
    Contributor

    Do you need it on netcore or desktop? this fix is only netcore at the moment, it's probably possible to get it into desktop as well if the code in that version is pretty similar.

  18. ErikEJ commented on Dec 12, 2019

    @ErikEJ
    Contributor

    If it is for EF Core, it will always be the .NET Core SqlClient

  19. cheenamalhotra commented on Dec 12, 2019

    @cheenamalhotra
    Member

    Hi @loth0

    Our next preview release containing the fix is planned in mid-January, after which you should be able to custom import the new preview Microsoft.Data.SqlClient package in your application with EF Core 3.1.

    EF Core should in future upgrade the dependency version for Microsoft.Data.SqlClient, but for their timelines you'll need to check with them.

  20. jsgoupil commented on Jan 28, 2020

    @jsgoupil

    @cheenamalhotra When will we know when this is fixed? Because I have EF Core 3.1.1 and I can still repro this problem.

  21. cheenamalhotra commented on Jan 28, 2020

    @cheenamalhotra
    Member

    @jsgoupil

    Since the fix was released in v2.0.0-preview1 of Microsoft.Data.SqlClient, you need to add custom reference to this version to get this fix:

    <PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0-preview1.20021.1" />
    
  22. juliusfriedman commented on Feb 20, 2020

    @juliusfriedman

    See also NetTopologySuite/NetTopologySuite#383, it seems the work around is to use a smaller string for now.

  23. loth0 commented on Aug 31, 2020

    @loth0

    Have this been included in latest EF Core (3.1.7)? i.e can I remove my package reference to Microsoft.Data.SqlClient?

  24. cheenamalhotra commented on Aug 31, 2020

    @cheenamalhotra
    Member

    Hi @loth0

    EF Core seems to use SqlClient v2.0.0 starting 5.0.0-preview versions:
    https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/5.0.0-preview.7.20365.15

    While v3.1.7 depends on M.D.S v1.1.3 that does not contain this fix.

  25. roji commented on Aug 31, 2020

    @roji
    Member

    @loth0 it should be fine to use EF Core 3.1.7 and to take an explicit dependency on SqlClient 2.0.1 - that version just isn't brought in by default, that's all.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions