Solved

linkedserver errors when you drop and add it

Posted on 2012-03-23
1
545 Views
Last Modified: 2012-03-26
Hi,

my script contains

USE MyDB
Drop user linkedserver
Create User linkedserver For Login linkedserver
Exec sp_addrolemember 'db_owner', 'linkedserver

Then I got the following error:
-Cannot drop the user 'linkedserver', because it does not exist or you do not
have permission.

I changed my script to
IF EXISTS(SELECT * FROM sys.database_principals WHERE name = 'linkedserver')
begin
          Drop user linkedserver
end

and then to
IF EXISTS(SELECT * FROM sys.database_principals WHERE name = 'linkedserver')
begin
          Alter authorization on schema::linkedserver to dbo
          Drop user linkedserver
end

However, it seemed to work for one db but caused another error on a different db.
The errors I am getting are:
-Cannot drop the user 'linkedserver', because it does not exist or you do not
have permission.
-The database principal owns a schema in the database, and cannot be dropped.
-User, group, or role 'linkedserver' already exists in the current database.
-Cannot find the schema 'linkedserver', because it does not exist or you do not
have permission.

How should I reconstruct my script to resolve all the issues I stated above at the same time?
Plz help~
0
Comment
Question by:IzzyTwinkly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
Deepak Chauhan earned 500 total points
ID: 37760105
Hi

use this script it will be work for you....

SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('linkedserver');

result will be >>> "db_owner"

then run this

ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;

go
drop user linkedserver.

>>
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question