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:
- 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. - Native SQL Statements: Entering custom SQL directly into the SQL statement box or using the
Value.NativeQueryfunction 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.
- Open Excel.
- Navigate to Data > Get Data > Query Options (or File > Options > Data > Query Options).
- In the left navigation pane, locate the Global category and click Security.
- In the main panel, find the Native Database Queries section.
- Uncheck the box labeled Require user approval for new native database queries.
- 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.
- Connect to SQL Server using SSMS.
- 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'; - 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.
- Open the Registry Editor (
regedit.exe). - Navigate to the Power Query security policy hive:
HKEY_CURRENT_USER\Software\Microsoft\Microsoft Power BI\SecurityorHKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Security - Create a new
DWORD (32-bit) Value. - Name the value:
DisableNativeQueryApproval - 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:
- Background Worker Failures: If removing the interactive warning allows the query to run, but background jobs still terminate, inspect worker thread permissions using Fixing “The background refresh of ‘Query’ failed.”.
- Authentication Barriers: If scheduled scripts fail because stored user credentials expire, review your identity configuration in Troubleshooting MFA (Multi-Factor Authentication) prompts that break background refreshes..
- Syntax Validation: If native queries fail immediately after execution approval is granted, verify that your SQL statement meets Excel’s subquery wrapping rules using Fixing “The SQL statement is not valid” (Syntax mismatches between T-SQL and Excel)..