Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fixing SQL Server Error 558: Remote Calls Blocked in Stored Procedures

· 9 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Identify the problematic stored procedures:
    1. Open SQL Server Management Studio (SSMS) and connect to your database.
    2. Expand the "Programmability" section in the Object Explorer and navigate to "Stored Procedures."
    3. Right-click each stored procedure and select "Script Stored Procedure as" > "CREATE To" (or use the sp_helptext procedure to view contents).
    4. Search for keywords like EXEC, sp_, OPENROWSET, or calls to remote services (e.g., sys.fn_dts_get_execution_info).
    5. If using SQL Server 2012+, check for EXECUTE AS OWNER or ASSEMBLY permissions that might trigger RPC. Use sp_configure to verify remote procedure calls are enabled globally: EXEC sp_configure 'remote access', 1; RECONFIGURE (This is typically disabled by default, but check with SHOWCONFIGUREDPARAMETERS for confirmation.)
    Note: Labels for stored procedures may differ slightly across SQL Server versions (e.g., "Extended Properties" might appear as "Advanced" in earlier versions).
  2. Disable RPC for the specific stored procedures:
    1. 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 (Replace ENCRYPTION with NOENCRYPTION if needed for security reasons.)
    2. For stored procedures referencing remote objects, use the WITH RECOMPILE option to force a non-RPC execution path: GO CREATE PROCEDURE dbo.MyRemoteCallProcedure WITH RECOMPILE AS BEGIN SET NOCOUNT ON; -- Your logic here END
    3. 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.
    Important: If the procedure references user-defined functions (UDFs) or assemblies, ensure those objects are also configured to avoid RPC. Check their ALTER FUNCTION or ALTER ASSEMBLY definitions for similar clauses.
  3. Check for cluster-specific configurations:
    1. 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 return IsClusteredInstance as 1.
    2. On a cluster, modify the sqlagent.ini file (located in the SQL Server instance directory) to set UseRemoteRPC=No. Restart the SQL Server service after changes.
    3. For SQL Server 2008 and earlier, check the sqlagent.ini file explicitly for RPC-related settings. In newer versions, this configuration is typically handled through sp_configure.
    Note: Modifying sqlagent.ini is platform-specific. On Windows, find it in %ProgramFiles%\Microsoft SQL Server\MSSQL.x\MSSQL\Binn\sqlagent.ini (replace x with your instance number). On Linux, consult your OS-specific documentation.
  4. Verify permissions and execute rights:
    1. 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 like db_datareader or db_ddladmin.)
    2. Check for conflicting EXECUTE AS clauses within the stored procedure tree. If a parent procedure sets EXECUTE AS OWNER, child procedures may inherit RPC permissions.
    3. 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.
    Safety: Always test in a non-production environment before applying changes to critical databases.
  5. Restart services if necessary:
    1. If changes to sqlagent.ini or sp_configure were made, restart the SQL Server and related services: net stop MSSQLSERVER net start MSSQLSERVER (On Linux: sudo systemctl restart sqlserver.)
    2. For clustered environments, restart the SQL Server Agent service specifically: sqlagent.exe -restart (Check the SQL Server documentation for your specific agent version.)
    Note: Restarting services may cause temporary performance dips during procedure execution.

Common Mistakes

  1. Overlooking nested stored procedures:

    Stored procedures can invoke other stored procedures, which may themselves contain RPC calls. Use a recursive search (e.g., sp_helptext on 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.

  2. Ignoring triggers and functions:

    Error 558 can manifest when triggers or user-defined functions (UDFs) reference remote objects. Audit the sys.triggers and sys.objects catalog views for calls to sp_* or OPENROWSET. Fix those dependencies first.

  3. Misconfiguring sp_configure:

    While sp_configure can enable/disable remote access globally, incorrect values may cause unintended behavior. Always verify with SHOWCONFIGUREDPARAMETERS before applying changes. For example, setting remote access to 1 when it's already 0 will require reconfiguring all RPC-based procedures.

  4. Skipping the WITH RECOMPILE clause:

    Using WITH RECOMPILE bypasses 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

  1. 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 a WITH RECOMPILE block.

  2. 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.

  3. Consider alternatives for distributed queries:

    If you must call remote services, use OPENROWSET with 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

  4. Monitor for recurring errors:

    After resolving the issue, set up alerts for error 558 using ERRORLOG or third-party tools like SQL Server Profiler. This ensures new RPC calls aren't silently introduced later.

  5. Document changes:

    Update your database schema documentation to note any forced non-RPC configurations. This helps future developers avoid reintroducing remote calls.

Troubleshooting

  1. The error persists after altering procedures:
    1. Check for cached procedures. Run DBCC FREEPROCACHE to clear the plan cache.
    2. 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';
    3. Restart SQL Server and the SQL Server Agent service. This forces a fresh load of stored procedures.
    If that does not work: Rebuild the database from backup, ensuring no hidden RPC calls exist in the original or restored state.
  2. You're using SQL Server Agent:
    1. Check the agent job steps for calls to remote databases. Configure jobs to use local system accounts or explicitly enable RPC via sp_add_jobstep with RemoteServer parameter set to 0. Example: sp_add_jobstep @job_name = 'MyJob', @step_name = 'MyStep', @command = 'EXEC dbo.MyProcedure', @database_name = 'YourDB', @remote_server = 0
    2. If using a clustered SQL Server, ensure the agent service is configured to avoid RPC: sqlagent.ini UseRemoteRPC=No
    Note: SQL Server Agent jobs may not always respect local RPC settings; test with SET REMOTE PROCEDURES OUT in the job step definition.
  3. The error occurs in replication scenarios:
    1. If using SQL Server replication, check the pubsub.ini or replication agent settings. Remote calls may be permitted during replication but blocked elsewhere.
    2. For Transactional Replication, ensure the replication agent is configured to use UseRemoteRPC=No in its sqlagent.ini file.
    3. Modify replication agents to use local SQL Server instances for synchronization. This avoids RPC entirely.
    Critical: If replication is critical, consult Microsoft's official documentation for version-specific RPC configuration details. Older versions (pre-2012) have stricter defaults.
  4. You're using a linked server:
    1. 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.)
    2. 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
    Note: Linked servers may have their own RPC settings; verify with sp_help linkedserver.
  5. The error still occurs after all steps:
    1. Check the SQL Server error logs for additional error messages. Look for entries related to procedure execution or RPC failures.
    2. Enable RPC logging temporarily to trace the call path: sp_configure 'remote access logging', 1; RECONFIGURE Search the error logs for lines like [Microsoft][SQL Server Native Client] RPC error.
    3. 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.
    Final step: If all else fails, create a new database with identical structure and test your procedures. If they work in the new database, the issue is likely with the original database's configuration or object definitions.

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.