Possible Duplicate:
SQL Server: Is there an “IF EXISTS” test for a linked server?
I am trying to create a block of code that will Create a Link Server/Drop a link server. I had posted similar question about adding and dropping a function and the solution was to drop the function and re-create it.
So I want to take the same approach with the LinkServer. DROP it and Re-create it every time I run this code.
However, I cannot re-create the link server after dropping and I get the error message: Server already exists.
Here is my code:
IF OBJECT_ID('AccessDataSource') IS NOT NULL
EXEC master.sys.sp_dropserver 'AccessDataSource','droplogins'
GO
EXEC sp_addlinkedserver
@server = 'AccessDataSource'
,@srvproduct = 'OLE DB Provider for ACE '
,@provider = 'Microsoft.ACE.OLEDB.12.0'
,@datasrc = 'N:\Database_Tools\AccessDB\delphi.accdb'
GO