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

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

Closed
malekpour opened this issue Jul 7, 2015 · 10 comments
Closed

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

malekpour opened this issue Jul 7, 2015 · 10 comments
Assignees
Milestone

Comments

@malekpour
Copy link

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
Copy link
Contributor

Hey,

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

~Rowan

@malekpour
Copy link
Author

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
Copy link
Author

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
Copy link
Contributor

@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
Copy link

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
Copy link
Contributor

@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
Copy link

@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
Copy link
Contributor

@dazinator 👍

@tangbao0002
Copy link

I had the same error, and when I add 'MultipleActiveResultSets=true' in my connection string, the error was disappeared.

@roji
Copy link
Member

roji commented Jan 26, 2022

@tbluesky2012 that sounds like a SqlClient bug, can you open an issue with a code sample on https://github.com/dotnet/SqlClient?

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants