Skip to content

Est. 2011ยทMicrosoft Partner 7033487ยทDelivery under 3 minยทSupport 7 days a week

Your vault is empty.

Free Fix 7202

Error 7202: Linked Server Missing From sys.servers and Ad Hoc Query Blocks

12 min read Updated October 5, 2026 SQL Server

Fix it now

Error 7202 means the first part of your four-part name is not registered in sys.servers on this instance, so nothing was ever sent to the network. Error 7415 is a different refusal: ad hoc access through OPENROWSET and OPENDATASOURCE is denied for that provider. Register the linked server, or enable ad hoc access deliberately.

Run these on the instance that raised the error, in order

SELECT name, product, provider, data_source, is_linked FROM sys.servers;
SELECT @@SERVERNAME AS Registered, SERVERPROPERTY('MachineName') AS Machine;
EXEC sp_addlinkedserver @server = N'SALESSRV', @srvproduct = N'', @provider = N'MSOLEDBSQL', @datasrc = N'sqlhost01\SALES';
EXEC sp_testlinkedserver N'SALESSRV';
  1. Read the first result. If the name in your query is not in that list, that is the whole answer and the third statement creates it.
  2. Check the second result before anything else. Two different values mean the machine was renamed and @@SERVERNAME is stale, which produces 7202 against your own instance.
  3. Map the login the application will use with sp_addlinkedsrvlogin rather than leaving the default, then rerun the query as that account and not as yourself.
  4. If you got 7415 instead, no linked server is missing. Either rewrite the statement against a linked server, or turn on the Ad Hoc Distributed Queries option knowing what it opens up.

sp_addlinkedserver has a short form for another SQL Server: EXECUTE sp_addlinkedserver N'SEATTLESales', N'SQL Server';. When @srvproduct is SQL Server, the provider, data source and catalogue arguments are not needed.

If the four-part name resolves now you can stop here. If not, the next section explains what the engine is looking up and why the network never enters into it.

Why it happens

A four-part name is server, database, schema, object. The engine resolves the first part against sys.servers, a catalogue table holding this instance’s own name plus every linked or remote server explicitly registered on it. If the name is not in that table, resolution stops. No DNS lookup happens and no connection is attempted, which is why 7202 comes back instantly and looks identical whether the remote machine is running, switched off or entirely fictional.

The published text says so directly: could not find the server in sys.servers, verify the server name, and if necessary run sp_addlinkedserver to add it. It is a registration error with a registration fix. It is also raised at severity 11 rather than the 16 most of the linked-server family use, which is worth knowing when you are scanning a log for something more dramatic.

sys.servers also holds the instance’s own name, written by sp_addserver at install time. Rename the machine afterwards and @@SERVERNAME keeps returning the old name, so any script that qualifies objects with the current machine name gets 7202 against its own instance. Comparing @@SERVERNAME with SERVERPROPERTY('MachineName') settles that in one query.

7415 guards something else entirely. OPENROWSET and OPENDATASOURCE let a statement name a provider and a connection string inline, with no registration, no login mapping and nothing in the catalogue to audit. Microsoft’s own wording is that enabling ad hoc names means any authenticated SQL Server account can reach the provider, and that these functions should be used only for data sources accessed infrequently. The option is off by default, and turning it on is a decision about the instance’s attack surface.

The linked server was never created on this instance

You have this one if sys.servers has no matching row, and the same query works on another server where somebody set it up years ago.

  1. Create it. For another SQL Server the short form is enough: EXECUTE sp_addlinkedserver N'sqlhost01\SALES', N'SQL Server';
  2. For an explicit provider, use Microsoft’s own shape: @srvproduct = N'', @provider = N'MSOLEDBSQL', @datasrc = N'sqlhost01\SALES'.
  3. Map the login with sp_addlinkedsrvlogin, then confirm with EXEC sp_testlinkedserver N'SALESSRV';, which raises the reason for the failure if the test does not pass.

Linked servers are instance-level objects. Restoring a database, failing over an availability group or rebuilding a server does not carry them across. Script them into source control with the rest of your instance configuration.

The registered name is not the name in the query

You have this one if sys.servers contains something similar: an alias, a fully qualified name, or the same host with a different instance suffix.

  1. Read the exact value from sys.servers and use that spelling in the four-part name.
  2. If application code depends on the other spelling, register a second linked server under that name pointing at the same source.
  3. Retest both names so you know which one your jobs and reports actually use.

The local server name is stale after a machine rename

You have this one if SELECT @@SERVERNAME, SERVERPROPERTY('MachineName'); returns two different values, and the name in the error is this machine.

  1. Drop the old entry and register the new one: EXECUTE sp_dropserver '<old_name>'; then EXECUTE sp_addserver '<new_name>', local;
  2. For a named instance use the full host\instance form on both statements.
  3. Restart the SQL Server service. Microsoft’s procedure requires the restart; the value does not change until then.

Microsoft does not support renaming a computer involved in replication, except log shipping with replication, and database mirroring has to be turned off before the rename and re-established afterwards. Check both before you touch the name.

Ad hoc distributed queries are switched off

You have this one if 7415, and only from statements using OPENROWSET or OPENDATASOURCE. Four-part names against registered linked servers work normally.

  1. Decide first whether a linked server would do. It gives you a login mapping, a catalogue entry and something to audit.
  2. If ad hoc access is genuinely required, enable it with the statements below and confirm the run value changed.
  3. Restrict who can execute the code that uses it, because the option is instance-wide.

Microsoft’s guidance is that OPENROWSET and OPENDATASOURCE are for data sources reached infrequently, and that anything accessed more than a few times should be a linked server.

The name resolves but the object or its metadata does not

You have this one if 7314, 7311, 7320 or 7350 instead of 7202. The linked server is found; the query against it is not satisfied.

  1. Read 7314 carefully: the published text says the table either does not exist or the current user has no permissions on it. Test both.
  2. Prove it with a pass-through: SELECT * FROM OPENQUERY(SALESSRV, 'SELECT TOP 1 * FROM dbo.YourTable');
  3. For 7320, the message ends with the provider’s own text. That trailing sentence is the actual error, not the 7320.

Full reference

Turning ad hoc access on, the way Microsoft publishes it

Instance-wide. Record why you did it

USE master;
GO
EXECUTE sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXECUTE sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
EXECUTE sp_configure 'show advanced options', 0;
GO
RECONFIGURE;
GO

Ad Hoc Distributed Queries is an advanced option, so show advanced options has to be 1 before sp_configure will even acknowledge the name. Without it you get error 15123, the configuration option does not exist or it may be an advanced option, which reads like a typo and is not one.

Which refusal you are looking at

What you see Where the fault is
7202 for a name you expected to exist The linked server was never created on this instance
7202 naming your own server @@SERVERNAME is stale after a machine rename
7202 in an Agent job but not in SSMS The job runs on a different instance from the one you tested against
7415 from OPENROWSET or OPENDATASOURCE Ad hoc access is denied for that provider, by design
7314 The remote table does not exist, or the mapped login cannot see it
7320 The provider refused the query. Its own message is appended to the error
7350 Column metadata could not be obtained from the provider
7311 The provider cannot supply the schema rowset a four-part name needs

Procedures worth knowing

Statement What it does
sp_addlinkedserver Registers a linked server. With @srvproduct = N'SQL Server' the other arguments are optional
sp_addlinkedsrvlogin Maps a local login to credentials used on the remote side
sp_testlinkedserver Tests the connection and raises an exception with the reason if it fails
sp_dropserver / sp_addserver Corrects the instance’s own registered name after a machine rename. Needs a service restart
OPENQUERY Sends your text to the remote server to parse in its own dialect and returns only the result

Why 7311 pushes you towards OPENQUERY

A four-part name asks the provider for a schema rowset so the local optimiser can plan across both sides. 7311’s published text is precise about the failure mode: the provider supports the interface but returns a failure code when it is used. That is a provider limitation, not something you configure away. OPENQUERY avoids the requirement entirely because the remote side parses and executes the text itself and hands back a result, so it is the workable route for providers that cannot describe their own schema.

Choosing between a four-part name and OPENQUERY

  • A four-part name lets the local optimiser plan across both instances, which is convenient and can drag whole tables back before filtering.
  • OPENQUERY sends your statement to the remote server, so filtering and aggregation happen there and only the result crosses.
  • Non-SQL Server providers frequently have dialects the local parser will not accept. OPENQUERY sidesteps that.
  • OPENQUERY takes a literal string, so parameters have to be composed carefully. Prefer a stored procedure on the remote side over building the text locally.

When the query works for you and fails for the application

7314’s published text names permissions as one of its two causes, and that is the case people skip. The linked server login mapping decides which remote credentials are used, and a mapping that works for your Windows account can resolve to something with no rights for a service account. Test as the account that actually runs the workload, not as a sysadmin, and check the mapping with sp_helplinkedsrvlogin before concluding the remote object is missing.

Agent jobs that fail while SSMS succeeds

  • Confirm which instance owns the job. A job on a second instance on the same machine has its own sys.servers.
  • Confirm the job step’s database context. A step that runs in master resolves unqualified names differently from your query window.
  • Confirm the step’s run-as account, then list sys.servers and test the linked server as that account.
  • If the step uses OPENROWSET, remember the Ad Hoc Distributed Queries option is instance-wide, so it may be on where you tested and off where the job runs.

Every code this article covers

Code What it points at Source
7202 The server named in the four-part name is not registered in sys.servers on this instance Microsoft Learn
7415 Ad hoc access to the named OLE DB provider has been denied; the provider must be reached through a linked server Microsoft Learn
7314 The provider for the linked server does not contain that table: it either does not exist, or the current user has no permission on it Microsoft Learn
7320 The query could not be executed against the provider for that linked server; the provider’s own message is appended Microsoft Learn
7350 Column information could not be obtained from the provider for that linked server Microsoft Learn
7311 The schema rowset could not be obtained: the provider supports the interface but returns a failure code when it is used Microsoft Learn

Confirm the fix worked

  1. SELECT name FROM sys.servers; returns the exact name your query uses.
  2. EXEC sp_testlinkedserver N'<name>'; completes without raising anything.
  3. SELECT @@SERVERNAME, SERVERPROPERTY('MachineName'); returns two matching values.
  4. The four-part-name query returns rows under the account the application uses, not only under yours.
  5. If you enabled ad hoc access, EXEC sp_configure 'Ad Hoc Distributed Queries'; shows a run value of 1 and you have written down why.

Questions people ask about this

Is enabling ad hoc distributed queries dangerous?

It widens what any authenticated account can reach from inside the instance, using credentials embedded in the statement and with no catalogue entry to audit. Microsoft’s own guidance is to enable it only for providers that are safe for any local account to reach, and to define a linked server for anything used more than occasionally.

Does a linked server need its own licence?

No, and nothing in this article costs anything to fix. Linked servers are part of the engine and are present in every edition. Both instances still need licensing in their own right, but connecting them adds nothing.

Why does my Agent job fail with 7202 when the query works in SSMS?

Almost always because the job runs on a different instance from the one your query window is connected to, or under a different account. Linked servers are instance-level, so check which instance owns the job and list sys.servers there.

I renamed the server. Do I have to fix @@SERVERNAME?

Yes, and Microsoft publishes the procedure: sp_dropserver for the old name, sp_addserver with local for the new one, then a service restart. Check first that the machine is not involved in replication or database mirroring, because the rename is not supported for the former and requires reconfiguring the latter.

Should I use OPENQUERY or a four-part name?

Use OPENQUERY when the remote side should do the work, when the provider has its own dialect, or when you are getting 7311. Use a four-part name when you want the local optimiser to plan across both and the volumes are small enough that it does not drag whole tables back.

Related error codes

Was this article helpful?

Your feedback helps us improve our documentation.

Related articles

Free Fix Errors 823, 824 and 825: I/O Errors That Signal Real Storage Damage License Error Error 40544: The Azure SQL Database Has Reached Its Size Quota License Error Error 41131: Failed to Bring the Availability Group Online License Error Error 33111: Cannot Find Server Certificate When Restoring a TDE Backup
โ† Back to Knowledge Base