SQL Server 2019 Behavior change with scope of SET IDENTITY_INSERT ON/OFF - identity-insert

We are migrating to SQL Server 2019 RTM version and noticed that one of our stored procedures that uses SET IDENTITY_INSERT ON/OFF statements are failing which works properly in SQL Server 2017 and earlier.
Even changing the compatibility level to SQL Server 2017 does not work the same way in SQL Server 2019. This looks like a bug/behavior change that is not documented anywhere.
Anyone encountering similar issues or know if it is a reported problem? I tried searching for it but another person who reported the issue was a combination of ODBC and SQL Server 2019 CTP versions.
We have lots of customers running earlier versions of our product on SQL Server 2017 and earlier with this stored procedure that we cannot afford to change but still want to migrate to SQL Server 2019 and now this has become a show stopper for our SQL Server 2019 migrations.
Here is code snippet that fails in SQL Server 2019 but works fine in SQL Server 2017 and before
How to reproduce the behavior.
CREATE PROC proc_inner
AS
BEGIN
SET IDENTITY_INSERT [#TMP_MESSAGE] ON;
INSERT INTO [#TMP_MESSAGE] (DCORP, ENTITYKEY, SEQNO, MESSAGE)
SELECT
'test', 1, 1, 'bdkfsjk';
SET IDENTITY_INSERT #TMP_MESSAGE OFF;
END;
GO
CREATE PROC proc_outer
AS
BEGIN
IF OBJECT_ID('TEMPDB..[#TMP_MESSAGE]') IS NULL
BEGIN
CREATE TABLE [#TMP_MESSAGE]
(
DCORP CHAR(10),
ENTITYKEY INT,
SEQNO INT IDENTITY(1, 1),
MESSAGE VARCHAR(8000)
);
END;
EXEC proc_inner;
SELECT *
FROM #TMP_MESSAGE;
END;
GO
EXEC proc_outer; -- this statement fails on SQL 2019
In SQL Server 2019 we get this error:
Msg 544, Level 16, State 1, Procedure proc_inner, Line 5 [Batch Start Line 36]
Cannot insert explicit value for identity column in table '#TMP_MESSAGE' when IDENTITY_INSERT is set to OFF. (0 rows affected)
In SQL Server 2017 and earlier, the same statement works properly.

I received a notification from MS support that it is in fact a bug with the new functionality so in case if anyone has issues with it the temporary workaround is to disable the feature using two trace flags:
====
In the meantime if anyone has upgraded to SQL 2019 (or for any plans) the workarounds are
Is to disable the new feature (reduced compilations for temporary tables) by enabling the trace flags
Even if we move to regular tables (non-temp table) we wont face this issue (but as this is will be a product level change- I don’t think it will be feasible at this point of time);
So the feasible workaround until we fix this issue :
Enabling the trace flag 11036;11048 at the SQL Startup Parameters ;

Related

DBMS_OUTPUT PL SQL code in Oracle sql developer not show the output

Running this, I see no output other than 'completed'
set serveroutput on
declare
message varchar2(20) := 'Hello, World';
begin
dbms_output.put_line(message);
end;
/
I have seen this behavior before, and it's always because your database is too old.
Are you using something older than 11gR2 on the database? If so, our newer jdbc drivers no longer support DMBS_OUTPUT polling on 9i and 10g of the Database.
Your options are:
find an older copy of SQL Developer, which uses an older JDBC driver or
Upgrade your database to something from this decade (19c would be best)
Obviously option 1 is the easiest and option 2 is the most desirable.

SSIS error with Oracle - Exception deserialzing the package "Value does not fall within the expected range"

I am taking an existing SQL Server 2016 SSIS package and trying to add an Execute SQL Task. I'm suspicious that the task itself isn't the problem, but just in case, I'll explain it.
It is a simple task to query the count in a table, using an existing OLE connection. I create a user variable, set the ResultSet to Single Row, and put in my statement: "SELECT COUNT(fld) FROM MY_TABLE" It shows no errors, but when I try to execute it, I get the error in the title. I can change it to a BEGIN SELECT COUNT(fld) FROM MY_TABLE; END; or add a GO on the 2nd line - it makes no difference. I can set the ResultSet to None, and it makes no difference. I can create a new OLE Connection and use that, and it makes no difference.
I'm pretty sure it has to do with the Oracle driver, because nothing in the paragraph above makes any sense. I can test the connection and it works, however, and when I use the existing connection, it is parameterized for the project.
So what next? Reinstall the Oracle drivers? Or is there anything less drastic?
I started a new project, make a new OLE connection, a new Execute SQL task, and call an Oracle procedure. It works just fine. It's just trying to edit an existing project that doesn't work. Sometimes.
Oh, I'm also using Visual Studio 2019.

ORA-01036: illegal variable name/number with Oracle 18 and Oracle 19 Windows client

After upgrading from Oracle 11/12 to 18/19 I get this error: ORA-01036: illegal variable name/number.
The error occurred in a query like this:
SELECT * FROM (SELECT * FROM TABLE) MY_TABLE WHERE ROWNUM <= :P_ROWNUM
(Subquery + binding parameters)
The identical query works properly with the Oracle 11.2.0.4 or 12.1.0.2 client. It fails with the Oracle Client 18c or 19c.
PS: The Oracle Server is version 18c 64x for Windows.
I use Delphi 10.1.2 with ADO components (dbGO). I also tried with Delphi 13.3.3 but the behavior is the same.
It seems to be a problem in the Oracle OLE DB provider (ORAOLEDB).
If I don't use ADO but DevArt Unidac all worked as expected.
Someone can help me?
Max
Your query is fine. We ran into a similar issue when migrating from 12.1 to 19. In our case, we have a custom OLE DB provider that interfaces with OraOLEDB (and others) using the Microsoft OLE DB Provider Templates (ATL). When attempting to upgrade from 12.1.x to 19c we started seeing the strange and confusing "ORA-01036: illegal variable name/number" error for parameterized SELECT queries. The queries would succeed the first time they were executed but subsequent executions would fail when all we did was change the parameter value (the queries were executed sequentially). I went on a wild goose chase trying to diagnose the issue and finally decided it had to be an Oracle caching bug of some kind. Yesterday, I experimented with the cache-related connection string attributes and found that adding the MetaDataCacheSize attribute and setting its value to 0 (zero) resolved the issue for us. None of the current Oracle patches appear to address this issue, at least none of those that mention the ORA-01036 error.

SQL data extracts works in Oracle 11g but not Oracle 12c

When I execute the following SQL using TOAD against an Oracle 11g database, the fully formed XML is returned successfully:
With T As (SELECT dbms_xmlgen.getxml('SELECT m.trans_message FROM xml_nodes_ams_in a, message m WHERE a.id = m.msg_id AND a.UPN IN(''A30971016528VE8K'',''A30971016529VE84'') ORDER BY a.upn ASC'
) As output_xml from dual
) select dbms_xmlgen.Convert(output_xml,1) from T
However, when I execute the exact same SQL against our newly installed Oracle 12c database, some of the XML data appears to be missing (around 5000 characters).
I have discussed this with the DBA who reckons its a client issue rather than a database issue as he says there is no setting against the database that would cause this.
Has anyone got any advise on how I can progress this issue?
I raised a service request with Oracle and they came back to me and advised that there is a bug with the dbms_xmlgen.Convert function within Oracle 12.1 that was fixed in Oracle 12.2. Basically the function fails with XML greater than 120 KB.

Debugging an Oracle PL/SQL WEB Application hangs browser and dev tool

I am fairly new to PL/SQL and have been assigned to maintain a PL/SQL system that uses WEB pages generated with PL/SQL as a front end (PL/SQL Web Application?). Because of the complexity of the application, I am trying to get the debugger from Oracle Developer Tools for Visual Studio (11.2.0.3.15) or Oracle's SQL Developer working.
I can not kick off the application from the development environment, so I am using the
DBMS_DEBUG_JDWP.CONNECT_TCP('10.15.1.177', '4000') and DBMS_DEBUG_JDWP.DISCONNECT() procedures in the package that I am trying to debug.
When the Oracle debug listener is started in Visual Studio, Tools -> Start Oracle External Application Debugger, this message appears in the output window:
PL/SQL Debugger starts. PL/SQL Debugger is listening on host:
10.15.1.177 and port: 4000.
In Oracle SQL Developer this message is shown
Debug listener (port=4000 Timeout=0 Local address=10.15.1.177)
Using Visual Studio, If the webpage is accessed and there are no breakpoints, the following messages appears the output window.
A database has connected to the PL/SQL Debugger on host: 10.15.1.177
and port: 4000. The thread 0x1 has exited with code 0 (0x0). A
database has disconnected from the PL/SQL Debugger on host:10.15.1.177
and port: 4000.
If there is a break-point anywhere in the package, before, between, or after the DBMS_DEBUG_JDWP statements, both the WEB browser and the development environment hang. Visual Studio sits with "Not Responding" until it is terminated.
In Oracle SQL Developer the WEB page hangs. If the listener is stopped then the web page can not be displayed because there is no listener available.
I do not have control over the Oracle server, but since it established a connection, I assume there is no firewall blocking the port.?
Does someone have an idea what I missed?
I have been told that you can not debug PL/SQL packages that generate web pages, but have not found any documentation indicating that is a problem.
I have been working with mod_plsql for quite some time and in my personal experience the best (if not only) way to debug such an application is to instrument your source code.
The debugger(s) works fine for pl/sql code that can be execute outside the browser but for code the interacts with mod_plsql it is in my experience best to instrument the code with tracing and logging message and use them to follow the program flow.
We use a quite sophisticated logging framework but it all comes down to a simple table where to store the log messages and an (autonomous) procedure that inserts log messages in this table.
Example:
CREATE TABLE logtab (id NUMBER, when DATE, text VARCHAR2(2000));
CREATE SEQUENCE logseq;
CREATE OR REPLACE
PROCEDURE dolog(text IN VARCHAR2)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO logtab (id, when, text) VALUES (logseq.NEXTVAL, SYSDATE, SUBSTR(text, 1, 2000));
COMMIT;
END dolog;
/
EXECUTE dolog('test');

Resources