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

The SqlDbType enumeration value, 240, is invalid. #2555

Closed
malekpour opened this Issue Jul 7, 2015 · 8 comments

Comments

Projects
None yet
3 participants
@malekpour

malekpour commented Jul 7, 2015

When current profile is dnxcore50 calling SqlDataReader.NextResult or NextResultAsync throws exception with following message:

{"The SqlDbType enumeration value, 240, is invalid.\r\nParameter name: SqlDbType"}

Stack trace:

   at System.Data.SqlClient.MetaType.GetSqlDataType(Int32 tdsType, UInt32 userType, Int32 length)
   at System.Data.SqlClient.TdsParser.TryCommonProcessMetaData(TdsParserStateObject stateObj, _SqlMetaData col)
   at System.Data.SqlClient.TdsParser.TryProcessMetaData(Int32 cColumns, TdsParserStateObject stateObj, _SqlMetaDataSet& metaData)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.TryNextResult(Boolean& more)
   at System.Data.SqlClient.SqlDataReader.<>c__DisplayClass0.<NextResultAsync>b__1(Task t)
   at System.Data.SqlClient.SqlDataReader.InvokeRetryable[T](Func`2 moreFunc, TaskCompletionSource`1 source, IDisposable objectToDispose)
@rowanmiller

This comment has been minimized.

Member

rowanmiller commented Jul 14, 2015

Hey,

Are you hitting this with EF7? Can you provide some code we can use to reproduce the issue?

~Rowan

@malekpour

This comment has been minimized.

malekpour commented Jul 14, 2015

Hi, Not EF7, just pure SqlDataReader. Here is the code...

public async Task Main(string[] args)
{
    var constr = @"Data Source=.\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True";

    var query = @"
SELECT * FROM [AdventureWorks].[Person].[Person]
SELECT * FROM [AdventureWorks].[Person].[Address]
";
    using (var connection = new SqlConnection(constr))
    using (var command = new SqlCommand(query, connection))
    {
        command.Connection.Open();

        var reader = await command.ExecuteReaderAsync();

        while (await reader.ReadAsync())
        {
        }

        await reader.NextResultAsync(); // Error happens here only on CoreClr

        while (await reader.ReadAsync())
        {
        }
    }
}
  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.Data": ""
      }    
    },
    "dnxcore50": {
      "dependencies": {
        "System.Data.SqlClient": "4.0.0-*",
        "System.Console": "4.0.0-*",
        "System.Collections": "4.0.10-*",
        "System.Linq": "4.0.0-*",
        "System.Threading": "4.0.10-*",
        "Microsoft.CSharp": "4.0.0-*"
      }
    }
  }
@malekpour

This comment has been minimized.

malekpour commented Jul 14, 2015

Also this may help since it happens only after second SELECT * statements.

public void Main(string[] args)
{
    var constr = @"Data Source=.\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True";

    var query = @"
SELECT * FROM [AdventureWorks].[Person].[Person]                -- okay
SELECT [ModifiedDate] FROM [AdventureWorks].[Person].[Address]  -- okay
SELECT * FROM [AdventureWorks].[Person].[Address]               -- error
";
    using (var connection = new SqlConnection(constr))
    using (var command = new SqlCommand(query, connection))
    {
        command.Connection.Open();

        var reader = command.ExecuteReader();

        while (reader.Read())
        {
        }

        reader.NextResult();

        while (reader.Read())
        {
        }

        reader.NextResult();

        while (reader.Read())
        {
        }
    }
}
@rowanmiller

This comment has been minimized.

Member

rowanmiller commented Jul 24, 2015

@malekpour I've contacted the SQL Client team to take a look at this one. They aren't on GitHub, so I'll leave this issue open until we have confirmation from them that the issue is being tracked elsewhere.

@rowanmiller rowanmiller added this to the Discussions milestone Jul 24, 2015

@rowanmiller rowanmiller self-assigned this Jul 24, 2015

@dazinator

This comment has been minimized.

dazinator commented Feb 23, 2016

Is there any update to this issue?

I am using EF7 and have started randomly getting a similar error: only it says it's type 0 is not valid:

image

@rowanmiller

This comment has been minimized.

Member

rowanmiller commented Feb 23, 2016

@dazinator the original issue from this bug was fixed a while back. Could you open a new issue for the SQL Client team on https://github.com/dotnet/corefx.

@dazinator

This comment has been minimized.

dazinator commented Feb 23, 2016

@rowanmiller - I fixed a bug today in our implementation, where we wern't managing the liftetime of DbContext correctly - i.e some were resolved by the IServiceProvider at the application services level rather than RequestServices and so were not being disposed, and were sometimes being re-used accorss different requests. I have a feeling that this may not have been helping matters. Now that this is fixed, if I still encounter the above error then I will be sure to raise an issue, otherwise I will assume this was the cause ;)

@rowanmiller

This comment has been minimized.

Member

rowanmiller commented Feb 23, 2016

@dazinator 👍

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