2
votes

EDIT 20210601, as an update:

This has been confirmed to be a bug, few weeks ago we've got an email from a support engineer saying they have implemented new logic for Elastic Query (still in Public Preview) which had this side effect. The workaround is to specify conversions (ex. nvarchar for text etc). For our case - the logic has been reverted so our solutions work on the previously affected servers, as I understand there will be a new release which will not have this bug.

Original question:

I have 3 Azure SQL databases: A, B and C

Database C is the source of data, databases A and B have external tables to that database. The definition of external tables is identical.

In the last couple of days something has changed - queries used to load data do not work in database A anymore. However, they still work in database B.

To start with, this query works in both databases:

SELECT * FROM < external table to database C >

But this query works only in database B but not database A:

SELECT 'test' FROM < external table to database C >

The error message:

Msg 46836, Level 16, State 2, Line 1
External table schema does not match actual schema from remote table: Mismatch between actual and expected type of column 1 in the remote query result. Expected: VARCHAR, Actual: NVARCHAR

Same error when trying other datatypes like datetime - it wants datetime2.

So, I've tried to convert the data type first and then it works in both databases:

SELECT CAST('test' AS nvarchar(10)) FROM < external table to database C >

This still does not work (same error which is weird because it says expecting varchar):

SELECT CAST('test' AS varchar(10)) FROM < external table to database C >

Any ideas what causes this?

Specifically why the difference between databases for the same query? And how can this change happen, I'm 100% sure there were no changes in configuration of the server or databases from my side.

4
I think the external table definition changed. It is not having right datatype compared to source table.Venkataraman R
Its not the external table - if I remove the hardcoded value I add in databases A and B then there is no problem in either database. And the external table definition is the same, using the same source table. I've edited the question after some more testing.Alex_404
Got the same issue in 3 of my subscriptionsNils E Lie
I can confirm we also have this issue in our Azure SQL databases. Version: Microsoft SQL Azure (RTM) - 12.0.2000.8 Apr 19 2021 17:05:18 Copyright (C) 2019 Microsoft Corporation Solution for now was to change SELECT 'club' to SELECT N'club'Tim Geerts

4 Answers

2
votes

I've got the same problem exactly on 2 out of 3 Azure databases.

The 2 ones causing trouble have version (SELECT @@VERSION), i.e. newer: Microsoft SQL Azure (RTM) - 12.0.2000.8 Apr 19 2021 17:05:18 Copyright (C) 2019 Microsoft Corporation

The one still working OK has version: Microsoft SQL Azure (RTM) - 12.0.2000.8 Feb 4 2021 02:12:36 Copyright (C) 2019 Microsoft Corporation

Is it possible for you to downgrade to 12.0.2000.8 Feb 4 2021 02:12:36 and see if you still have the problem?

I think Microsoft introduced a bug between February and April regarding this.

2
votes

Quick update on this issue. We were experiencing this issue for about 10 days. We have contacted Microsoft sql server support team and Yes. Its 100% Microsoft introduced issue. I was told that this bug is going to be fixed within 1 to 2 months.

1
votes

This is a bug in Azure - report it through the portal. Not all servers have this issue.

To check if MS has sorted it out for you, run "DBCC FREEPROCCACHE" and try again.

Edit: The same bug also has an effect on CASE WHEN when using external tables.

0
votes

In case it helps anyone else, the workaround for us was to cast the VARCHAR column to NVARCHAR before calling - in our case - REPLACE. I.e. instead of

select REPLACE(MyCol,'-','')
from MyExternalTable

we did

select REPLACE(CAST(MyCol AS NVARCHAR(20)),'-','')
from MyExternalTable