Showing posts with label errormessage. Show all posts
Showing posts with label errormessage. Show all posts

Friday, January 24, 2020

ANSI_WARNINGS = OFF can break update statements with some SQL features


Working on a SQL 2017 database where an external, non-Microsoft application has direct access to read/write data via the ODBC Driver 17 for SQL Server.

They suddenly began to experience a regression, UPDATE statements were failing with the following message snippet:

 esu_sql_execute (SQLExecute) : [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]
UPDATE failed because the following SET options have incorrect settings:
'ANSI_WARNINGS'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications
and/or XML data type methods and/or spatial index operations.

esu_sql_execute (SQLExecute) : [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.

Right away, I figured that something in the database from the above list of options was incompatible with the legacy ANSI_WARNINGS = OFF setting the external developers were using in their code. And I was resigned quickly to the fact that something in SQL Server would have to change, as this project was nearing a time-sensitive milestone.

Though ANSI_WARNINGS = OFF is not recommended, changing it in an existing application is problematic. Development should begin with ANSI_WARNINGS = ON and ANSI_DEFAULTS = ON, but if it doesn't, changing these settings requires a LOT of regression testing, especially around the behavior of NULL values in aggregate functions, divide-by-zero and artithmetic error handling, and how trailing blanks are handled. So yeah, it gets messy and time-consuming.

As the error message above had said, I quickly looked through the database for the SQL features listed in the error message (above). All of these features of SQL Server have incompatibilities with the legacy ANSI_WARNINGS = OFF setting. 

Sure enough, we had added a very beneficial filtered index recently to help with some lookups on a table where only a minority of the records had a status we were interested in. 

The filter was removed, performance gain lost, the UPDATE statements started working again.

Monday, October 21, 2019

SSIS Scaleout: Cannot open certificate store on the machine

When attempting to connect a worker node to the current Master node of a SQL Server Integration Services (SSIS) Scaleout, for on-prem SQL Servers, if you receive the error:

Validation Error(s):
Cannot open certificate store on the machine

First off, launch SSMS on the SQL Server instance you intend to be the master. The steps to troubleshoot start with the two steps here:
https://docs.microsoft.com/en-us/sql/integration-services/scale-out/troubleshooting-scale-out#cannot-open-certificate-store

"1. Run Scale Out Manager as administrator. If you open Scale Out Manager with SSMS, you have to run SSMS as administrator.
2. Start the Remote Registry service on the computer if it is not running."
3. Finally, if you are trying to add a named instance, there is one more gotcha. The Scaleout Worker is the server name not the SQL Instance name. Do not provide the full named instance name, for example, "SQLSERVER-1\INSTANCENAME", only provide the server name, in this case, "SQLSERVER-1".





Friday, February 01, 2019

"A connection timeout has occurred on a previously established connection to availability replica"

I previously spent some time troubleshooting this issue at one client, and then having encountered it twice more this year, I figured I'd include it in a blog post. Yep, the fix, which is delivered in a CU for SQL 2012, 2014, or 2016 does fix the issue.
Message 35201: A connection timeout has occurred while attempting to establish a connection to availability replica 'replicaname' with id [availability_group_id]. Either a networking or firewall issue exists, or the endpoint address provided for the replica is not the database mirroring endpoint of the host server instance. 
Message 35206: A connection timeout has occurred on a previously established connection to availability replica 'replicaname' with id [availability_group_id]. Either a networking or a firewall issue exists or the availability replica has transitioned to the resolving role.
If you are troubleshooting the above errors, make sure you are on one of these versions (or later)*
  • SQL Server 2016 RTM CU5 or SP1 CU1
  • SQL Server 2014 SP2 CU4
  • SQL Server 2012 SP3 CU7 
*This patch was out before SQL Server 2017 was released, SQL 2017 is not susceptible.

This issue was very problematic because as databases stopped synchronizing, the log files on the primary replica continued to grow. This would eventually create an outage once the volume filled to capacity. Despite all our best efforts, like the KB article says, there's no fix other than rebooting the secondary or removing/recreating the replica. Obviously rebooting/removing the secondary replica doesn't necessarily impact production, but it does impact high availability.

I have encountered this error in multiple environments, once in an Availability Group with 50+ databases, and another also with just 3 databases, one of which had constant high-transactional volume. According to the KB article, "This problem might occur only on very powerful computers and when SQL Server is very busy. For example, in one scenario, this problem occurred on a very busy system with 24 cores."

Thursday, August 15, 2013

Distribution setup SQL Server Agent error: "RegCreateKeyEx() returned error 5, 'Access is denied.'"

In the Configure Distribution Wizard, the step "Configuring SQL Server Agent to start automatically" errors with the following text:
TITLE: Configure Distribution Wizard
------------------------------
An error occurred configuring SQL Server Agent.
------------------------------
ADDITIONAL INFORMATION:
RegCreateKeyEx() returned error 5, 'Access is denied.' (Microsoft SQL Server, Error: 22002)


This is a very minor error, and not difficult to work around at all. The wizard is attempting to change the SQL Server Agent service "Start Mode" to Automatic. You can do this via the SQL Server Configuration Manager instead.

In the Sysinternals Process Monitor, you may see: Operation: RegCreateKey Result: ACCESS DENIED Path: "HKLM\System\CurrentControlSet\Services\SQLAgent$SQL2012"

If you encounter this error, select "No" in the "SQL Server Agent Start" page in the Configure Distribution Wizard (as shown below), and then set your agent service to Automatic Start Mode via the SQL Server Configuration Manager.


















The third step of the wizard that failed before will not happen.

Why the failure actually occurs I did not figure this out, and I'm open to feedback, but this seems like a vestigial step to a wizard that otherwise has no negative impact. Running SSMS with "run as Administrator" does not appear to fix this error either. I'd love to know why this error happens in the first place.

Thursday, February 28, 2013

"An item with the same key has already been added."

In SQL Server Reporting Services, when adding a new dataset to a report, you may see an error that looks like this:

"An item with the same key has already been added."




















Based on some quick googling, it looks like there are several potential causes for the error, but here's why I received it today.

The stored procedure I had declared as the query source had the same column name declared twice.  Even if you use different data from different tables, even if you declare them differently, SSRS needs all column names in the final dataset to be unique.
select

tablea.samecolumnname

,tableb.samecolumnname

,samecolumnname = tablec.columnname

,tabled.columnname as samecolumnname

...
That error message isn't helpful, but that was the solution for me, for what was a clumsy mistake to begin with.

Monday, August 20, 2012

SQL Agent Alerts - Severity Condition is NOT "greater than or equal to"

I ran into some bad training that had convinced a client sys admin that the SQL Agent Alerts had the "greater than or equal to property."

As in, if I want to catch and notify an operator of all high severity errors 17 through 25, all I needed to do was set up an Alert for Severity 17.  This is false.

Here's a quick proof:

USE [msdb]
GO

--This query will not run in a batch for obvious reasons.  The high-severity error messages will kill the batch.
--Run each statement manually and observe the results.

EXEC msdb.dbo.sp_add_alert @name=N'020',
              @message_id=0,
              @severity=20,
              @enabled=1,
              @delay_between_responses=0,
              @include_event_description_in=1,
              @job_id=N'00000000-0000-0000-0000-000000000000'
GO
--This query will return date and time 0 | 0.  The new alert exists.
select name, last_occurrence_date, last_occurrence_time from msdb.dbo.sysalerts where name = '020'
GO
RAISERROR (N'testingonly.  This is message %s %d.', -- Message text.
           21, -- Severity,
           1, -- State,
           N'number', -- First argument.
           5) WITH LOG; -- Second argument.
GO
--This query will still return date and time 0 | 0.  Alert for Severity 20 has NOT been triggered by a Severity 21 error.
select name, last_occurrence_date, last_occurrence_time from msdb.dbo.sysalerts where name = '020'
GO
RAISERROR (N'testingonly.  This is message %s %d.', -- Message text.
           20, -- Severity,
           1, -- State,
           N'number', -- First argument.
           5) WITH LOG; -- Second argument.
GO
--This query will return a valid date and time.  Alert for Severity 20 has been triggered by a Severity 20 error.
select name, last_occurrence_date, last_occurrence_time from msdb.dbo.sysalerts where name = '020'
GO


As you run the above script statement-by-statement (NOT in a batch), you'll see the occurrence data trigger only for an error with the severity EQUALS the defined alert state.  In this case, the Severity 21 error did NOT trigger the Severity 20 alert.

Here's a basic script from my toolbox to set up Alerts for all significant error severities, to notify your operator via email with details.  In this script, the operator is called "DBAs", and ideally would be a distribution group for all active members of the Database Administrator role in your IT department.

Make sure that database mail is setup, that SQL Agent is configured to use the appropriate Database Mail profile, and that the failsafe operator is enabled to email your DBA team.  

USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 17',
              @message_id=0,
              @severity=17,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 17', @operator_name=N'DBAs', @notification_method = 1
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 18',
              @message_id=0,
              @severity=18,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 18', @operator_name=N'DBAs', @notification_method = 1
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 19',
              @message_id=0,
              @severity=19,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 19', @operator_name=N'DBAs', @notification_method = 1
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 20',
              @message_id=0,
              @severity=20,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 20', @operator_name=N'DBAs', @notification_method = 1
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 21',
              @message_id=0,
              @severity=21,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 21', @operator_name=N'DBAs', @notification_method = 1
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 22',
              @message_id=0,
              @severity=22,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 22', @operator_name=N'DBAs', @notification_method = 1
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 23',
              @message_id=0,
              @severity=23,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 23', @operator_name=N'DBAs', @notification_method = 1
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 24',
              @message_id=0,
              @severity=24,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 24', @operator_name=N'DBAs', @notification_method = 1
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'errorseverity 25',
              @message_id=0,
              @severity=25,
              @enabled=1,
              @delay_between_responses=600,
              @include_event_description_in=1
GO
EXEC msdb.dbo.sp_add_notification @alert_name=N'errorseverity 25', @operator_name=N'DBAs', @notification_method = 1
GO


More info:
Error severity info: http://msdn.microsoft.com/en-us/library/ms164086.aspx

Tuesday, June 02, 2009

'Microsoft.AnalysisServices.DsvTableBinding' to type 'Microsoft.AnalysisServices.QueryBinding'

One of the things this blog intends to do is help speed up the troubleshooting process by documenting strange errors like this.

Here's an interesting error message that came up today which has surprisingly little web coverage.

"Unable to cast object of type 'Microsoft.AnalysisServices.DsvTableBinding' to type 'Microsoft.AnalysisServices.QueryBinding'.

It is caused by trying to apply a querystring to an existing partition that is not query-driven in OMA. In this case, an SSIS 2005 vb.net app that builds partitions (by the hundreds for me) into a cube. Like many things, its one of those spend a while then slap your forehead problems that makes a ton of sense. Obviously, I can't set the partition query of a partition that is table-bound.

I do plan to post my ssis app once I am done with it. But until then, here's the blog post that inspired it.

"No question is so difficult to answer as that to which the answer is obvious." -George Bernard Shaw