Insert error from synapse data flow to SQL server DB

Lotus88 116 Reputation points
2025-02-19T06:30:20.1366667+00:00

Hi,

I am trying to capture an error throw by synapse data flow and insert to SQL DB table.

But I keep getting update error. I think the error contain single quote ', is there a way to insert the error to the table? Below is my code in Script activity:

insert into @{pipeline().parameters.logtable}

       (pl_run_id, error_log)

values ('@{pipeline().RunId}',

        '@{string(json(activity('DF Filter source with changed quotes').error.message).Message)}');

User's image

User's image

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,244 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,355 questions
{count} votes

Accepted answer
  1. Smaran Thoomu 21,505 Reputation points Microsoft External Staff
    2025-02-21T13:06:27.4933333+00:00

    Hi @Lotus88
    You’re absolutely right, trying to replace every special character manually can be a headache, especially when you don’t know all the characters that might cause issues.

    A better way to handle this is by using a stored procedure in SQL. Instead of inserting the error message directly in your query (which can break because of special characters), you can send it as a parameter, and SQL will take care of the rest.

    Here’s a better approach:

    • Modify your Script Activity to call a stored procedure instead of directly inserting the error log.
    • Create a stored procedure in SQL Server like this:
    CREATE PROCEDURE InsertErrorLog  
        @pl_run_id NVARCHAR(100),  
        @error_log NVARCHAR(MAX)  
    AS  
    BEGIN  
        INSERT INTO YourLogTable (pl_run_id, error_log)  
        VALUES (@pl_run_id, @error_log);   
    END
    
    • Call the stored procedure from Synapse using the Execute activity or Lookup activity in ADF.

    This way, SQL Server will handle escaping for you, and you won’t have to worry about special characters breaking the query.

    I hope this helps. Please let me know if you need further information.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.