Handling “Native Query” security warnings that block automation.

The “Native Database Query” security warning (displaying the message “Running this query may be unsafe. Do you want to run this query against your database?”) appears in Excel when Power Query executes an explicit SQL statement rather than using standard table-navigation steps. While intended to protect users from running malicious code embedded in unknown workbooks, this interactive prompt completely halts unattended automation, scheduled tasks, PowerShell batch updates, and background data refreshes because headless scripts cannot click the “Run” button.

Quick Answer

To stop the “Native Database Query” warning from breaking Excel automation, open Excel and go to Data > Get Data > Query Options. Under the Global heading, select Security, uncheck Require user approval for new native database queries, and click OK. Alternatively, encapsulate custom SQL inside a database View to bypass native query validation prompts entirely.


Why Excel Prompts for Native SQL Queries

Excel distinguishes between two ways of fetching database information:

  1. Catalog Navigation: Clicking through schemas, tables, and views using the standard Power Query interface (Sql.Database("Server", "DB"){[Schema="dbo",Item="Orders"]}[Data]). Excel considers this safe because it relies on standard, read-only metadata browsing.
  2. Native SQL Statements: Entering custom SQL directly into the SQL statement box or using the Value.NativeQuery function in M-code.

Because a custom SQL statement could theoretically contain destructive administrative scripts (DROP TABLE, DELETE, or EXEC xp_cmdshell), Excel flags any custom query string as an arbitrary execution risk.

When a human user operates Excel, clicking Run dismisses the prompt and stores an approval token in your Windows profile. However, during automated tasks—such as reports refreshed via Windows Task Scheduler or automated cloud pipelines—no user is present to dismiss the dialog. The worker process hangs until it hits an execution timeout.

To troubleshoot broader Trust Center restrictions affecting database connections, review Handling “The connection has been disabled” in Excel Trust Center settings..


Step-by-Step Fixes

Method 1: Disable Native Query Approval in Query Options

The most direct fix for dedicated reporting workstations and automation runners is disabling the approval requirement in Excel’s global configuration.

  1. Open Excel.
  2. Navigate to Data > Get Data > Query Options (or File > Options > Data > Query Options).
  3. In the left navigation pane, locate the Global category and click Security.
  4. In the main panel, find the Native Database Queries section.
  5. Uncheck the box labeled Require user approval for new native database queries.
  6. Click OK.

Once this option is disabled, Excel will immediately execute custom SQL queries inside Power Query without presenting interactive approval dialogs.

Method 2: Encapsulate SQL in a Database View (Best Enterprise Practice)

If corporate IT policies prohibit disabling security warnings on your desktop, you can bypass the native query security mechanism entirely by moving your custom SQL logic onto the database server inside a Database View.

  1. Connect to SQL Server using SSMS.
  2. Wrap your custom query into a permanent view: CREATE VIEW dbo.vw_DailyShipmentReport AS SELECT s.ShipmentID, s.ShipDate, c.CustomerName, s.FreightCost FROM dbo.Shipments AS s INNER JOIN dbo.Customers AS c ON s.CustomerID = c.CustomerID WHERE s.Status = 'Delivered';
  3. Open Excel and connect via standard catalog navigation:
    • Go to Data > Get Data > From Database > From SQL Server Database.
    • Enter your Server and Database name, but leave the SQL statement box completely empty.
    • In the Navigator window, select dbo.vw_DailyShipmentReport.

Because Excel treats views as standard catalog objects rather than unverified native query strings, the security warning will never appear, and the refresh will execute cleanly in automated scripts.

Method 3: Deploy the Enterprise Registry Key via GPO

For corporate network administrators managing reporting clusters or virtual desktop pools, you can enforce this setting across all client computers using the Windows Registry.

  1. Open the Registry Editor (regedit.exe).
  2. Navigate to the Power Query security policy hive:
    HKEY_CURRENT_USER\Software\Microsoft\Microsoft Power BI\Security orHKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Security
  3. Create a new DWORD (32-bit) Value.
  4. Name the value: DisableNativeQueryApproval
  5. Set its value data to 1.

This registry policy permanently silences the native database query prompt across all automated user sessions.


Diagnostic Next Steps

Once the native query warning is resolved and automation can run without interactive interruptions: