Fixing SQL Server Error 558: Remote Calls Blocked in Stored Procedures
In this article
Error 558 in SQL Server occurs when your stored procedures or functions attempt to call remote procedures or services, and Microsoft blocks these calls by default for security and compatibility reasons. The simplest fix is to disable remote procedure calls (RPC) in your stored procedure definitions, but deeper configuration changes may be needed if you rely on these calls for distributed queries or service-oriented architectures. To resolve this, you must either alter the stored procedure's access permissions, reconfigure the client-server communication, or restructure your workflow to avoid remote calls entirely.
What You'll Need
- Administrative access to your SQL Server instance (local or remote)
- A text editor or SQL Server Management Studio (SSMS) with permissions to alter objects
- Knowledge of your stored procedures' dependencies (remote calls, triggers, or functions that invoke RPC)
- Access to the server where SQL Server is installed (physical or virtual machine)
- Backup of the database if you modify schema extensively (recommended) – note: backups may not fully capture stored procedure definitions in all edge cases
Step-by-Step
- Identify the problematic stored procedures:
- Open SQL Server Management Studio (SSMS) and connect to your database.
- Expand the "Programmability" section in the Object Explorer and navigate to "Stored Procedures."
- Right-click each stored procedure and select "Script Stored Procedure as" > "CREATE To" (or use the
sp_helptextprocedure to view contents). - Search for keywords like
EXEC,sp_,OPENROWSET, or calls to remote services (e.g.,sys.fn_dts_get_execution_info). - If using SQL Server 2012+, check for
EXECUTE AS OWNERorASSEMBLYpermissions that might trigger RPC. Usesp_configureto verify remote procedure calls are enabled globally:EXEC sp_configure 'remote access', 1; RECONFIGURE(This is typically disabled by default, but check withSHOWCONFIGUREDPARAMETERSfor confirmation.)
- Disable RPC for the specific stored procedures:
- Once identified, alter each problematic stored procedure to explicitly disable RPC. Add the following clause to the procedure definition:
WITH SCHEMABINDING, ENCRYPTION, EXECUTE AS OWNER(ReplaceENCRYPTIONwithNOENCRYPTIONif needed for security reasons.) - For stored procedures referencing remote objects, use the
WITH RECOMPILEoption to force a non-RPC execution path:GO CREATE PROCEDURE dbo.MyRemoteCallProcedure WITH RECOMPILE AS BEGIN SET NOCOUNT ON; -- Your logic here END - If the procedure calls a remote service via
OPENROWSET, modify it to use local functions instead:SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Data Source=C:\data.accdb') AS MyData→ Replace with a local table import or direct query against a local database file.
ALTER FUNCTIONorALTER ASSEMBLYdefinitions for similar clauses. - Once identified, alter each problematic stored procedure to explicitly disable RPC. Add the following clause to the procedure definition:
- Check for cluster-specific configurations:
- If SQL Server is deployed in a clustered environment, RPC calls may be blocked by default. Verify this via
SELECT * FROM sys.dm_os_clustered_instance_info, which should returnIsClusteredInstanceas 1. - On a cluster, modify the
sqlagent.inifile (located in the SQL Server instance directory) to setUseRemoteRPC=No. Restart the SQL Server service after changes. - For SQL Server 2008 and earlier, check the
sqlagent.inifile explicitly for RPC-related settings. In newer versions, this configuration is typically handled throughsp_configure.
sqlagent.iniis platform-specific. On Windows, find it in%ProgramFiles%\Microsoft SQL Server\MSSQL.x\MSSQL\Binn\sqlagent.ini(replacexwith your instance number). On Linux, consult your OS-specific documentation. - If SQL Server is deployed in a clustered environment, RPC calls may be blocked by default. Verify this via
- Verify permissions and execute rights:
- Ensure the database user executing the stored procedure has explicit permissions to call non-RPC objects. Use:
EXEC sp_addrolemember 'db_owner', 'YourUserName';(Replace with appropriate roles likedb_datareaderordb_ddladmin.) - Check for conflicting
EXECUTE ASclauses within the stored procedure tree. If a parent procedure setsEXECUTE AS OWNER, child procedures may inherit RPC permissions. - For SQL Server 2012+, test with a fresh backup. Recover the database and compare the original procedure definitions to ensure no hidden modifications introduced RPC calls.
- Ensure the database user executing the stored procedure has explicit permissions to call non-RPC objects. Use:
- Restart services if necessary:
- If changes to
sqlagent.iniorsp_configurewere made, restart the SQL Server and related services:net stop MSSQLSERVER net start MSSQLSERVER(On Linux:sudo systemctl restart sqlserver.) - For clustered environments, restart the SQL Server Agent service specifically:
sqlagent.exe -restart(Check the SQL Server documentation for your specific agent version.)
- If changes to
Common Mistakes
- Overlooking nested stored procedures:
Stored procedures can invoke other stored procedures, which may themselves contain RPC calls. Use a recursive search (e.g.,
sp_helptexton all procedures) to audit the entire call tree. If a procedure calls a remote service indirectly, the error may persist even after altering the top-level procedure. - Ignoring triggers and functions:
Error 558 can manifest when triggers or user-defined functions (UDFs) reference remote objects. Audit the
sys.triggersandsys.objectscatalog views for calls tosp_*orOPENROWSET. Fix those dependencies first. - Misconfiguring sp_configure:
While
sp_configurecan enable/disable remote access globally, incorrect values may cause unintended behavior. Always verify withSHOWCONFIGUREDPARAMETERSbefore applying changes. For example, settingremote accessto 1 when it's already 0 will require reconfiguring all RPC-based procedures. - Skipping the WITH RECOMPILE clause:
Using
WITH RECOMPILEbypasses the default RPC checks, but it may lead to performance issues or schema changes if the procedure references dynamic SQL or external dependencies. Test thoroughly in a staging environment.
Tips
- Use dynamic SQL sparingly:
Dynamic SQL (e.g.,
EXEC('SELECT * FROM RemoteTable')) often triggers RPC calls. Replace with static queries or stored procedures where possible. If dynamic SQL is unavoidable, wrap it in aWITH RECOMPILEblock. - Audit remote calls systematically:
Write a script to identify all RPC-like calls in your database. Example:
SELECT name, definition FROM sys.sql_modules WHERE definition LIKE '%EXEC%' OR definition LIKE '%OPENROWSET%' OR definition LIKE '%sp_*'Use this script to pinpoint all problematic code. - Consider alternatives for distributed queries:
If you must call remote services, use
OPENROWSETwith a local data source (e.g., a flat file) instead of remote databases. This avoids RPC overhead entirely. For example:SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Data Source=C:\remote_data.accdb;') AS LocalData - Monitor for recurring errors:
After resolving the issue, set up alerts for error 558 using
ERRORLOGor third-party tools like SQL Server Profiler. This ensures new RPC calls aren't silently introduced later. - Document changes:
Update your database schema documentation to note any forced non-RPC configurations. This helps future developers avoid reintroducing remote calls.
Troubleshooting
- The error persists after altering procedures:
- Check for cached procedures. Run
DBCC FREEPROCACHEto clear the plan cache. - Verify the stored procedure definition isn't being overridden by a backup or shadow copy. Compare the object definition with
sp_helptext:EXEC sp_helptext 'dbo.MyProcedure'; - Restart SQL Server and the SQL Server Agent service. This forces a fresh load of stored procedures.
- Check for cached procedures. Run
- You're using SQL Server Agent:
- Check the agent job steps for calls to remote databases. Configure jobs to use local system accounts or explicitly enable RPC via
sp_add_jobstepwithRemoteServerparameter set to0. Example:sp_add_jobstep @job_name = 'MyJob', @step_name = 'MyStep', @command = 'EXEC dbo.MyProcedure', @database_name = 'YourDB', @remote_server = 0 - If using a clustered SQL Server, ensure the agent service is configured to avoid RPC:
sqlagent.ini UseRemoteRPC=No
SET REMOTE PROCEDURES OUTin the job step definition. - Check the agent job steps for calls to remote databases. Configure jobs to use local system accounts or explicitly enable RPC via
- The error occurs in replication scenarios:
- If using SQL Server replication, check the pubsub.ini or replication agent settings. Remote calls may be permitted during replication but blocked elsewhere.
- For Transactional Replication, ensure the replication agent is configured to use
UseRemoteRPC=Noin itssqlagent.inifile. - Modify replication agents to use local SQL Server instances for synchronization. This avoids RPC entirely.
- You're using a linked server:
- Check the linked server's configuration. If it allows RPC, disable it via:
ALTER SERVER PROPERTY ('Allow Remote RPC', 0)(This requires superuser permissions and may affect other components.) - Replace linked server calls with direct queries against the source database. Example:
-- Before (uses RPC): SELECT * FROM OPENQUERY(RemoteServer, 'SELECT * FROM SourceTable') -- After (local query): SELECT * FROM LocalServer.dbo.SourceTable
sp_help linkedserver. - Check the linked server's configuration. If it allows RPC, disable it via:
- The error still occurs after all steps:
- Check the SQL Server error logs for additional error messages. Look for entries related to procedure execution or RPC failures.
- Enable RPC logging temporarily to trace the call path:
sp_configure 'remote access logging', 1; RECONFIGURESearch the error logs for lines like[Microsoft][SQL Server Native Client] RPC error. - Run a full database scan to detect hidden objects:
EXEC sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'(This is for testing; do not use in production.) Check for tables referencing remote data sources.
Frequently Asked Questions
Why does SQL Server block RPC calls by default?
RPC calls enable communication between SQL Server instances, but they introduce security risks (e.g., data leakage, privilege escalation) and compatibility issues across versions. Microsoft disabled them by default to enforce secure, version-specific workflows. For example, RPC calls between SQL Server 2005 and 2019 may fail due to schema mismatches.
Can I enable RPC calls for specific users?
Not directly via SQL Server. Instead, grant users permissions to call remote procedures via linked servers or explicitly allow RPC in the sp_configure settings. For example:
GRANT EXECUTE ON [RemoteDatabase].[dbo].[RemoteProcedure] TO [YourUser]
(But this does not bypass the RPC block; it grants access to the remote object.)
What if I'm using SQL Server 2019 and get this error?
SQL Server 2019 enforces stricter RPC restrictions than earlier versions. If you must call remote services, use WITH RECOMPILE or restructure your queries to avoid remote calls entirely. For Azure SQL, consider OPENROWSET with local file connections instead of remote databases.
How do I test if my stored procedure is actually calling RPC?
Use this script to detect RPC-like activity:
SELECT
name AS ProcedureName,
definition AS Definition,
CASE WHEN definition LIKE '%EXEC%' THEN 1 ELSE 0 END AS HasEXEC,
CASE WHEN definition LIKE '%OPENROWSET%' THEN 1 ELSE 0 END AS HasOpenRowSet,
CASE WHEN definition LIKE '%sp_%' THEN 1 ELSE 0 END AS HasRemoteCalls
FROM sys.sql_modules
WHERE definition LIKE '%EXEC%'
OR definition LIKE '%OPENROWSET%'
OR definition LIKE '%sp_%'
Filter results by the HasRemoteCalls column.
Why is my stored procedure working on one server but not another?
This typically happens due to version discrepancies. RPC calls between different SQL Server versions may fail due to schema incompatibilities (e.g., column types, encryption settings). Test in a shared environment or ensure both servers use the same SQL Server edition.
Can I use this fix for remote queries in Azure SQL?
In Azure SQL, most RPC-like functionality is replaced by managed services. For example, use OPENROWSET with local file connections or Azure Data Factory for distributed queries. If you must use remote calls, contact Azure support to enable specific RPC configurations, as defaults are more restrictive than on-premises.