SQL Procedure getting exit upon called

Ruchita 40 Reputation points
2024-07-12T17:06:00.1433333+00:00

I have a sql stored procedure created which will be getting invoked for multiple tables and column sequence wise.There are multiple DDL scripts which have procedure call and these scripts will get executed via sqlcmd command.So there is a folder X which have Script1.SQL,Script2.SQL and so on.One by one the scripts from the path will be executed via sqlcmd.

Script1.SQL will have procedure call as example :

EXEC PROCEDURENAME 'TABLENAME', 'COLUMNNAME';

EXEC PROCEDURENAME 'TABLENAME', 'COLUMNNAME';

Script2.SQL will have :

EXEC PROCEDURENAME 'TABLENAME', 'COLUMNNAME';

EXEC PROCEDURENAME 'TABLENAME', 'COLUMNNAME';

The above are just examples so there will be multiple scripts with multiple lines of code having procedure call has above.

The procedure stops or is getting exited randomly.

There is no error or no error logs.

Below are the logs which are printed in procedure.

These logs are added in procedure to verify.

STARTS : MAPPING_LISTMASTERTABLES ColName : AUXPARAM

STARTS11

Jul 12 2024 6:19PM

Error Occurred1: Could not drop constraint. See previous errors.

STARTS12

Jul 12 2024 6:19PM

ENDS12

Jul 12 2024 6:19PM

STARTS13

Jul 12 2024 6:19PM

STARTS16

Jul 12 2024 6:19PM

Error Occurred3: Could not create constraint or index. See previous errors.

Execution Ends for \ddl\Master_List.sql

Executing\ddl\ModuleAndMenuTree.SQL


2024-07-12 18:19:58.150

(1 row affected)

STARTS11

Jul 12 2024 6:19PM

ENDS11

Jul 12 2024 6:19PM

STARTS12

Now if you see it stopped or exited dont know why.For other scripts it executed properly for next script it exited and this is random it exits for any script.

Now the logs are only till STARTS12 after that PRINT GETDATE() did not printed whereas for previous it worked.

Tried below things :

EXEC sp_configure 'query timeout', 1800; RECONFIGURE;

EXEC sp_configure 'show advanced options', 1; RECONFIGURE;

EXEC sp_configure 'remote query timeout', 1800; RECONFIGURE;

Still the same issue.If you rerun the scripts again it executes fine.

The issue is while first execution.Checked

EXEC xp_readerrorlog; no relevant logs

What can be the problem?And how to figure it?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,575 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 109.3K Reputation points MVP
    2024-07-12T22:25:19.4066667+00:00

    Tried below things : EXEC sp_configure 'query timeout', 1800; RECONFIGURE; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'remote query timeout', 1800; RECONFIGURE;

    Just to note: these are completely irrelevant to your problem.

    As Olaf noted, you dumped a bunch of T-SQL code, which is not exactly easy to read. You can try to clear it by using the View Markdown button and make sure that the code block is in a single set of three backticks.

    Then again, as Naomi suggests, the issue is most likely that your the DDL commands you generate run into errors. You have some debug output. You may have to improve that. I would recommend that you have a PRINT for every dynamic SQL statement you produce. Presumably the last one executed is the one that fails.


2 additional answers

Sort by: Most helpful
  1. Olaf Helper 43,896 Reputation points
    2024-07-12T17:50:03.2733333+00:00

    The procedure stops or is getting exited randomly. There is no error or no error logs.

    "Thanks" for posting tons of SQL code. We don't have your database to test anything and without an error message we can't guess anything.

    Please post an reproducable example, otherwise it's mor the difficult to assist you.


  2. Naomi Nosonovsky 565 Reputation points
    2024-07-12T20:41:25.0866667+00:00

    Well, in the output you posted I can see some errors like this Error Occurred1: Could not drop constraint. See previous errors.

    Can you investigate these errors?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.