Saturday, August 31, 2013

[SQL Server] error:Setuser failed because of one of the following reasons: the database principal 'schemaUser' does not exist,

[SQL Server] error:Setuser failed because of one of the following reasons: the database principal 'schemaUser' does not exist,


error:Setuser failed because of one of the following reasons: the database principal 'schemaUser' does not exist,

Posted: 30 Aug 2013 10:38 PM PDT

with reference to http://technet.microsoft.com/en-us/library/ms191534(v=sql.100).aspxI copy the commands word by word [quote]E. Granting VIEW DEFINITION permission on an XML schema collectionSETUSERGOUSE masterGOif exists( select * from sysdatabases where name='permissionsDB' ) drop database permissionsDBGOif exists( select * from sys.sql_logins where name='schemaUser' ) drop login schemaUserGOCREATE DATABASE permissionsDBGOCREATE LOGIN schemaUser WITH PASSWORD='Pass#123',DEFAULT_DATABASE=permissionsDBGOGRANT CONNECT SQL TO schemaUserGOUSE permissionsDBGOCREATE USER schemaUser WITH DEFAULT_SCHEMA=dboGOCREATE XML SCHEMA COLLECTION MySC AS '<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ns"xmlns:ns="http://ns"> <simpleType name="ListOfIntegers"> <list itemType="integer"/> </simpleType> <element name="root" type="ns:ListOfIntegers"/> <element name="gRoot" type="gMonth"/></schema>'GO-- schemaUser cannot see the contents of the collection.SETUSER 'schemaUser'GOSELECT XML_SCHEMA_NAMESPACE(N'dbo',N'MySC')GO-- Grant schemaUser VIEW DEFINITION and REFERENCES permissions-- on the xml schema collection.SETUSERGOGRANT VIEW DEFINITION ON XML SCHEMA COLLECTION::dbo.MySC TO schemaUserGOGRANT REFERENCES ON XML SCHEMA COLLECTION::dbo.MySC TO schemaUserGO-- Now schemaUser can see the content of the collection.SETUSER 'schemaUser'GOSELECT XML_SCHEMA_NAMESPACE(N'dbo',N'MySC')GO-- Revoke schemaUser VIEW DEFINITION permissions-- on the xml schema collection.SETUSERGOREVOKE VIEW DEFINITION ON XML SCHEMA COLLECTION::dbo.MySC FROM schemaUserGO-- Now schemaUser cannot see the contents of -- the collection anymore.SETUSER 'schemaUser'GOSELECT XML_SCHEMA_NAMESPACE(N'dbo',N'MySC')GO[/quote]every thing is working until [code]SETUSERGOREVOKE VIEW DEFINITION ON XML SCHEMA COLLECTION::dbo.MySC FROM schemaUserGO-- Now schemaUser cannot see the contents of -- the collection.setuser 'schemaUser'[/code]I encountered the following error:Setuser failed because of one of the following reasons: the database principal 'schemaUser' does not exist, its corresponding server principal does not have server access, this type of database principal cannot be impersonated, or you do not have permission.why is this is so? Is there any solution.thanks

No comments:

Post a Comment

Search This Blog