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

SqlConnectionX Instantiation via SqlConnection #2570

Closed
wants to merge 10 commits into from

Conversation

mdaigle
Copy link
Contributor

@mdaigle mdaigle commented Jun 12, 2024

No description provided.

@Wraith2
Copy link
Contributor

Wraith2 commented Jun 14, 2024

What is SqlConnectionX and why does it exist?

@David-Engel
Copy link
Contributor

David-Engel commented Jun 14, 2024

What is SqlConnectionX and why does it exist?

@Wraith2 Part of the SqlClientX project. The goal is to address core issues in SqlClient under an experimental code path in the existing package. You might find this project particularly interesting and your feedback and expertise would be beneficial, if you have time to take a look at the PRs coming in.

@@ -214,6 +228,11 @@ public SqlConnection(string connectionString, SqlCredential credential) : this()
// checking pool groups which is not necessary. All necessary operation is already done by calling "ConnectionString = connectionString"
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/ctorConnectionStringCredential/*' />
public SqlConnection(string connectionString, SqlCredential credential) : this(connectionString, credential, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of setting useExperimental to false, have you thought about setting it via AppContext switch that can be configured by user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to it. In practice, is AppContext only used like this article describes (as an opt-out mechanism for new behavior) or is it used as a general settings store? https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-appcontext

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible direction here is to use the DbDataSource abstraction as the factory for the new experimental connection objects (#2119 generally tracked introducing a SqlDataSourcei n SqlClient). In other words, you would have a SqlDataSourceBuilder which can produce a SqlDataSource with a particular configuration; one of these configurable options would be to produce "experimental" connections. The disadvantage of this method is that users must use the SqlDataSource mechanism to create such experimental connections (but people would have to modify their code in any case). @saurabh500 and I discussed these possibilities a bit.

Whatever's done, I'd recommend putting the [Experimental] attribute on any programmatic API here; this attribute was introduced in .NET 8.0, and causes a warning with a specific diagnostic ID to be reported when a user uses an API (the user can then decide to suppress that specific diagnostic ID). This would make it easier to remove later as an experimental, non-supported API etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roji, thanks! We do plan to follow the lead of npgsql and use the data source builder pattern. This is a start at integrating with the existing call pattern to reduce the burden of transitioning to the new implementation. The idea being we could seamlessly default you to the new driver if you're on the right .NET version and platform. But I'm thinking I'll shelve this PR for a bit until the other pieces are in place. I'm learning more about the builder and data source pattern as we implement those pieces and I think this PR will change slightly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! Please feel free to ping me or reach out on Teams with any questions.

I'd be maybe wary of varying the default implementation based on the .NET version targeted - it's quite unexpected for some to switch the targeted TFM and for SqlClient to suddenly be a completely different implementation. But anyway, I'm sure all this will be discussed at some point.

return _sqlConnectionX.OpenAsync(cancellationToken);
}

return IsProviderRetriable?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space before ?

@@ -33,6 +36,19 @@ public SqlConnection() : base()
_innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;
}

internal SqlConnection(bool useExperimental): this()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space before :

}
else
{
_innerConnection = DbConnectionClosedNeverOpened.SingletonInstance;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hasn't this assignment already happened on line 36?

{
}

internal SqlConnectionX(string connectionString, SqlCredential credential): this()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space before :

@mdaigle mdaigle force-pushed the sqlconnectionx-instantiation branch from 19e361e to e6fc7fc Compare June 20, 2024 16:43
@mdaigle mdaigle closed this Jun 21, 2024
@mdaigle mdaigle deleted the sqlconnectionx-instantiation branch June 21, 2024 17:38
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

Successfully merging this pull request may close these issues.

7 participants