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

MultipleActiveResultSets spelled wrong from SqlConnectionStringBuilder.ConnectionString #654

Closed
kondelik opened this issue Jul 17, 2020 · 5 comments

Comments

@kondelik
Copy link

kondelik commented Jul 17, 2020

Version: Microsoft.Data.SqlClient 2.0.0; .net47 (NuGet)

If i set MARS on Microsoft.Data.SqlConnectionstringBuilder to true then property ConnectionString will return "Multiple Active Result Sets=true;" which is wrong - there are spaces, it should be "MultipleActiveResultSets=true;" (see https://docs.microsoft.com/en/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets, https://www.sqlteam.com/articles/multiple-active-result-sets-mars, https://www.connectionstrings.com/microsoft-data-sqlclient/enable-mars/ etc)

Packages.config (fresh console project with Microsoft.Data.SqlClient nuget):

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Data.SqlClient" version="2.0.0" targetFramework="net47" />
  <package id="Microsoft.Data.SqlClient.SNI" version="2.0.0" targetFramework="net47" />
  <package id="Microsoft.Identity.Client" version="4.14.0" targetFramework="net47" />
  <package id="Microsoft.IdentityModel.JsonWebTokens" version="5.6.0" targetFramework="net47" />
  <package id="Microsoft.IdentityModel.Logging" version="5.6.0" targetFramework="net47" />
  <package id="Microsoft.IdentityModel.Protocols" version="5.6.0" targetFramework="net47" />
  <package id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="5.6.0" targetFramework="net47" />
  <package id="Microsoft.IdentityModel.Tokens" version="5.6.0" targetFramework="net47" />
  <package id="Newtonsoft.Json" version="10.0.1" targetFramework="net47" />
  <package id="System.IdentityModel.Tokens.Jwt" version="5.6.0" targetFramework="net47" />
</packages>

Issue reproduction:

var cb = new Microsoft.Data.SqlClient.SqlConnectionStringBuilder();
cb.MultipleActiveResultSets = true;
Console.WriteLine(cb.ConnectionString);
// "Multiple Active Result Sets=True" - wrong. Should be "MultipleActiveResultSets=True;"

or

(connection string is from https://www.connectionstrings.com/microsoft-data-sqlclient/enable-mars/)

var cb = new Microsoft.Data.SqlClient.SqlConnectionStringBuilder("Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;MultipleActiveResultSets=true;");
Console.WriteLine(cb.ConnectionString);
// "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;Multiple Active Result Sets=true;
// wrong. Should be "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;MultipleActiveResultSets=True;" - i send that to constructor.

Can post you repro, but its really just these few lines of code.

Workaround:

a) Dont update to 2.0.0 :)
b) just cb.ConnectionString.Replace("Multiple Active Result Sets", "MultipleActiveResultSets");

@kondelik
Copy link
Author

kondelik commented Jul 17, 2020

I think the bug is there:

internal const string MultipleActiveResultSets = "Multiple Active Result Sets";

in this PR: #534

(i am not sure)

@kondelik
Copy link
Author

kondelik commented Jul 17, 2020

Oh, i missed a key piece of information:

This is not backward compatible with (pretty much legacy, i know, but what can i do...) LinqToEntity - it throw ArgumentException about not recognizing 'Multiple Active Result Sets ' (i dont have exact wording, my exceptions are not in english)

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 17, 2020

@SPLITE Can you show the stack trace from your exception?
EF 6 does not use Microsoft.Data.SqlClient.

@kondelik
Copy link
Author

🤦‍♂️ oh my...

After closer inspection i am almost sure this is my bug (i am passing connection string where i should pass connection) - please give me few minutes to validate (how it could ever work...), then i will probably close this issue.

@kondelik
Copy link
Author

kondelik commented Jul 17, 2020

Well, closing.

I am sorry i bothered you 😊 This whole thing is my mistake.

For random googlers, there is what happened:

In our (really old) project, we use System.Data.Linq.DataContext (that is not Entity Framework, that is Entity Framework ancestor 🙂) which can be constructed with IDbConnection or connectionString or even file name.

Of course, everything work when you do something like

new System.Data.Linq.DbContext(
  new Microsoft.Data.SqlConnection(
    new Microsoft.Data.SqlConnectionBuilder(connectionString).ConnectionString
  )
)

(please dont do this, this is only example). But there was one service where that new Microsoft.Data.SqlConnection() was missing, so we passed

new System.Data.Linq.DbContext(
  Microsoft.Data.SqlConnectionBuilder(connectionString).ConnectionString // this is wrong.
)

only. And I did not notice... I was sure that I was sending connection and not connectionString. With dotPeek i found out this will auto-create System.Data.SqlClient - and this accidentally worked until "MultipleActiveResultSets" was changed to "Multiple Active Result Sets".

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

2 participants