Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add query notification support to SqlClient #20708

Merged
merged 1 commit into from
Jun 6, 2017
Merged

Add query notification support to SqlClient #20708

merged 1 commit into from
Jun 6, 2017

Conversation

corivera
Copy link
Member

@corivera corivera commented Jun 5, 2017

Addresses https://github.com/dotnet/corefx/issues/8188

Note that SqlCommand.NotificationAutoEnlist has been removed in this PR, since the underlying functionality for it does not exist. ASP.NET sets the auto enlist SqlDependency using CallContext.SetData(), but the CallContext.SetData/GetData methods are not available in .NET Core. The NotificationAutoEnlist property only checks for data set by ASP.NET, so the property has been removed to show that it's explicitly unsupported.

@corivera
Copy link
Member Author

corivera commented Jun 5, 2017

Investigating NetFx build failures.

{
if ((null != value) && (ushort.MaxValue < value.Length))
{
throw ADP.ArgumentOutOfRange(string.Empty, ADP.ParameterService);
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this is from the reference source, but should this be fixed to use nameof(Options) (along the lines of the other properties below) instead of ADP.ParameterService? Then the ParameterService const wouldn't need to be added.

Copy link
Member Author

@corivera corivera Jun 5, 2017

Choose a reason for hiding this comment

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

ParameterService has the value "Service" though, so the error message would be different from Framework.

Copy link
Member Author

@corivera corivera Jun 5, 2017

Choose a reason for hiding this comment

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

Options is used to set the Service Broker service name, which is why the argument is reported as "Service", I guess.
https://msdn.microsoft.com/en-us/library/system.data.sql.sqlnotificationrequest.options(v=vs.110).aspx

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. It looks like a bug in the desktop framework (the kind of bug that have been fixed in corefx).

Copy link
Member Author

Choose a reason for hiding this comment

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

@saurabh500 Should we make the ArgumentOutOfRange exception have the actual property name here, or use the legacy "Service" name?

Copy link
Member

Choose a reason for hiding this comment

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

FWIW we've in many places fixed the parameter name in Argument exceptions and don't consider it a breaking change at all.

@@ -1143,7 +1143,7 @@
"4.1.0.0": "4.1.0",
"4.1.1.0": "4.3.0",
"4.2.0.0": "4.4.0",
"4.2.1.0": "4.5.0"
"4.3.0.0": "4.5.0"
Copy link
Member Author

Choose a reason for hiding this comment

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

@weshaggard Should we bump to 4.2.2.0 or 4.3.0.0 here?

Copy link
Member

Choose a reason for hiding this comment

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

@ericstj to confirm but I think we should bump the version to 4.3.0.0 given we are adding new APIs.


// Constructors

[HostProtection(ExternalThreading = true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe HostProtection can be deleted. See #12081 (comment) and dotnet/coreclr#8610

{
if (timeout < 0)
{
throw SQL.InvalidSqlDependencyTimeout("timeout");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: nameof(timeout)

// and listen for a notification for the added commands.
if (command == null)
{
throw ADP.ArgumentNull("command");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: nameof(command)

{
if (null == connectionString)
{
throw ADP.ArgumentNull("connectionString");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: nameof(connectionString) here and below

{
if (_sqlDep != null)
{
_sqlDep.StartTimer(Notification);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there supposed to be a corresponding StopTimer as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like SqlDependency.Invalidate() handles that. There's no StopTimer() method in the Framework code.

private void AddCommandInternal(SqlCommand cmd)
{
if (cmd != null)
{ // Don't bother with BID if command null.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This BID comment seems unnecessary

}
}

internal SqlConnectionContainerHashHelper HashHelper
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This properties can be shorthanded HashHelper => _hashHelper

@danmoseley
Copy link
Member

The Ubuntu test failure in System.Data.SqlClient.Tests.DiagnosticTest.ExecuteScalarAsyncTest is tracked by https://github.com/dotnet/corefx/issues/20441 and https://github.com/dotnet/corefx/issues/17925 .. the full details are in the console output:

System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)

@corivera @saurabh500 this test seems to fail fairly regularly in this way (only some instances are linked in the issues). Is it potentially a product issue? Could one of you please take a look?

@corivera
Copy link
Member Author

corivera commented Jun 6, 2017

@danmosemsft That test uses a local test proxy to simulate a SQL server connection. The SQL error indicates that the proxy wasn't set up correctly, and the connection open attempt timed out. We've seen other connection issues with tests that use that test proxy code, so I suspect it's an issue with the test code itself.

@saurabh500 Thoughts?

@saurabh500
Copy link
Contributor

Yeah, I think we need to add more logs on the server side to figure out why the server didn't come up.
It's definitely an issue with the test server.

@corivera
Copy link
Member Author

corivera commented Jun 6, 2017

@dotnet-bot Test Linux x64 Tests - Debug - Ubuntu.1404.Amd64.Open please

@danmoseley
Copy link
Member

@corivera it's super confusing, but the unix test jobs all originate in a single build job, and that's the only thing that can be rerun. So
@dotnet-bot test Portable Linux x64 Debug Build please
@dotnet-bot test Portable Linux x64 Release Build please

@weshaggard is making this less confusing...

@danmoseley
Copy link
Member

@corivera fyi this went green.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants