Home
%3CLINGO-SUB%20id%3D%22lingo-sub-383138%22%20slang%3D%22en-US%22%3ESQL%20Linked%20Server%20Query%20failed%20with%20%E2%80%9CLogin%20failed%20for%20user%20%E2%80%A6%E2%80%9D%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-383138%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Aug%2010%2C%202006%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3ESQL%20Server%202005%3A%20%E2%80%9CLogin%20failed%20for%20user%20'NT%20AUTHORITYANONYMOUS%20LOGON'%E2%80%9D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESQL%20Server%202000%3A%20%22Login%20failed%20for%20user%20%22(null)%22.%20Reason%3A%20Not%20associated%20with%20a%20trusted%20SQL%20Server%20connection%22.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EThe%20errors%20listed%20above%20is%20very%20typical%20when%20deploy%20linked%20server%20with%20delegation.%20They%20actually%20are%20thrown%20by%20the%20linked%20server%20and%20pass%20by%20middle%20server%20to%20the%20client%20application.%20In%20this%20post%2C%20I%20will%20discuss%20how%20to%20properly%20configure%20SQL%20instances%20and%20Windows%20environment%20in%20most%20common%20scenario%20and%20try%20to%20make%20configuration%20steps%20as%20explicit%20as%20possible.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EBy%20using%20delegation%20in%20distributed%20query%2C%20such%20as%20linked%20server%20query%2C%20the%20SQL%20instance%20obtains%20impersonated%20token%20of%20the%20user%20logon%20credential%20to%20gain%20access%20to%20resources%20of%20another%20SQL%20instance%2C%20the%20linked%20server.%20In%20delegation%20setting%2C%20the%20client%20connection%20and%20linked%20server%20object%20are%20configured%20to%20use%20integrated%20authentication%20in%20SQL%20Server%E2%80%99s%20term%20as%20opposed%20to%20SQL%20login.%20Some%20time%20integrated%20authentication%20also%20referred%20as%20trusted%20connection%20or%20Windows%20authentication.%20Linked%20server%20login%20can%20also%20use%20SQL%20login%2C%20but%20it%20is%20not%20discussed%20here.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3ETo%20simplify%20the%20discussion%2C%20let%E2%80%99s%20assume%20two%20SQL%20Server%20instances%20are%20installed%20on%20machine%20A%20and%20B%20respectively.%20Also%2C%20let%E2%80%99s%20assume%20A%20is%20the%20middle%20server%20that%20has%20a%20linked%20server%20object%20configured%20which%20points%20to%20a%20SQL%20instance%20on%20machine%20B.%20If%20the%20client%20is%20on%20machine%20C%20different%20from%20A%2C%20we%20call%20it%20double-hop%20setting%3B%20if%20the%20client%20is%20collocated%20with%20middle%20server%20machine%20A%2C%20we%20call%20it%20single-hop%20setting.%20In%20single-hop%20setting%2C%20it%20is%20relatively%20straightforward%20to%20configure%20linked%20server%20to%20work.%20Believe%20or%20not%2C%20double-hop%20setting%20requires%20more%20careful%20configurations%20as%20you%20will%20see.%20This%20is%20because%20in%20single-hop%20setting%2C%20windows%20NTLM%20authentication%2C%20which%20is%20available%20in%20most%20common%20setting%20if%20all%20machines%20are%20windows%2C%20is%20sufficient%20for%20delegation%3B%20while%20in%20double-hop%20setting%2C%20Kerberos%20authentication%20is%20mandate%20for%20flowing%20user%E2%80%99s%20credential%20through%20machine%20boundaries%20from%20the%20client%20to%20the%20linked%20server.%20It%20requires%20windows%20domain%2C%20correct%20DNS%20name%20resolution%2C%20proper%20account%20setting%20in%20both%20Active%20Directory%20and%20SQL%20Server.%20%26nbsp%3BTo%20make%20sure%20Kerberos%20delegation%20%5B1%5D%20is%20correct%20becomes%20vital%20to%20operate%20distributed%20query%20with%20delegation.%20The%20authentication%20scheme%20required%20by%20delegation%20in%20different%20setting%20is%20illustrated%20by%20the%20following%20table.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CDIV%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CTABLE%3E%0A%20%20%20%20%3CTBODY%3E%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EAuthentication%20scheme%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EC%20to%20A%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EA%20to%20B%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%20%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ESingle%20hop%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ENTLM%20or%20Kerberos%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E(C%20is%20on%20the%20same%20box%20as%20A)%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ENTLM%20or%20Kerberos%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%20%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EDouble%20hops%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EKerberos%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EKerberos%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%3C%2FTBODY%3E%3C%2FTABLE%3E%0A%20%20%3C%2FDIV%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CB%3E%20%5BCreate%20Linked%20Server%20Object%20on%20Middle%20Server%5D%20%3C%2FB%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EBefore%20getting%20into%20details%20on%20how%20to%20configure%20other%20components%2C%20since%20I%20am%20talking%20about%20delegation%20in%20the%20context%20of%20SQL%20Server%20distributed%20query%2C%20let%E2%80%99s%20first%20give%20an%20example%20on%20how%20to%20configure%20a%20linked%20server%20object%20on%20A%20and%20set%20up%20its%20login%20to%20use%20delegation.%20%26nbsp%3BTo%20do%20so%2C%20you%20need%20the%20following%20two%20steps.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(1)%20Use%20sp_addlinkedserver%20to%20create%20a%20linked%20server%20object%20and%20name%20it%20%E2%80%9CLinkedServer%E2%80%9D%20which%20points%20to%20the%20SQL%20instance%20on%20machine%20B%2C%20SQLB.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9CEXEC%20sp_addlinkedserver%20%40server%3D%E2%80%99LinkedServer%E2%80%99%2C%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%40srvproduct%3D''%E2%80%9D%2C%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%40provider%3D'SQLNCLI'%2C%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%40datasrc%3D%E2%80%99SQLB%E2%80%99%2C--the%20data%20source%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%40provstr%3D%22Integrated%20Security%3DSSPI%3B%20%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9C%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3ETo%20verify%20if%20the%20command%20is%20executed%20correctly%2C%20run%20query%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9Cselect%20*%20from%20sys.servers%20where%20name%3D'LinkedServer'%E2%80%9D%3B%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(2)%20Use%20sp_addlinkedsrvlogin%20to%20configure%20login%20to%20use%20self-mapping%20as%20following%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9Cexec%20sp_addlinkedsrvlogin%20%E2%80%98LinkedServer%E2%80%99%2C%20'true'%E2%80%9D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EStep%20(2)%20makes%20middle%20server%20A%20try%20to%20use%20impersonated%20token%20of%20user%20to%20authenticate%20to%20server%20B.%20To%20verify%20that%20the%20linked%20server%20is%20setup%20for%20%E2%80%9Cself-mapping%E2%80%9D%2C%20run%20query%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9Cselect%20uses_self_credential%20as%20delegation%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3Efrom%20sys.linked_logins%20as%20L%2C%20sys.servers%20as%20S%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3Ewhere%20S.server_id%3DL.server_id%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3Eand%20S.name%3DN'LinkedServer'%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EThe%20resulting%20table%20should%20show%20the%20delegation%20column%20is%20%E2%80%9C1%E2%80%9D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CB%3E%20%5BTest%20Linked%20Server%20Query%20in%20Single-hop%20Settting%5D%20%3C%2FB%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EBefore%20test-drive%20a%20link%20server%20query%20in%20single-hop%20setting%2C%20you%20need%20also%20make%20sure%20that%20the%20client%20user%20can%20make%20direct%20query%20to%20the%20SQL%20instances%20on%20both%20A%20and%20B.%20This%20means%20that%20the%20user%20account%2C%20either%20windows%20domain%20account%20or%20a%20machine%20account%2C%20must%20have%20permission%20to%20access%20both%20SQL%20instances.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(3)%20To%20verify%20the%20user%20domain%20account%20has%20permission%20to%20access%20both%20SQL%20instances%2C%20use%20your%20favorite%20client%20tool%2C%20for%20example%2C%E2%80%9Cosql%20%E2%80%93E%20%E2%80%93S%20SQLA%E2%80%9D%20and%20%E2%80%9Cosql%20%E2%80%93E%20%E2%80%93S%20SQLB%E2%80%9D.%20If%20you%20are%20failing%20for%20whatever%20reason%2C%20please%20refer%20to%20%5B5%5D%5B6%5D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(4)%20To%20test%20linked%20server%20query%2C%20run%20query%20at%20SQLA%2C%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9Cselect%20*%20from%20LinkedServer.master.dbo.sysdatabases%E2%80%9D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CB%3E%20%5BConfigure%20and%20Test%20Double-hop%20Setting%5D%20%3C%2FB%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3ETo%20deploy%20delegation%20based%20linked%20server%20in%20double-hop%20setting%2C%20the%20followings%20need%20to%20be%20configured%20correctly.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(3)%26nbsp%3B%26nbsp%3B%20Kerberos%20in%20Windows%20mandates%20Windows%20domain.%20Therefore%20the%20user%20account%20needs%20to%20be%20a%20domain%20account%20and%20middle%20server%20and%20linked%20server%20need%20to%20join%20a%20domain.%20All%20machines%20involved%20in%20the%20delegation%2C%20including%20client%20machine%2C%20middle%20server%20and%20linked%20server%2C%20must%20have%20good%20TCP%2FIP%20connectivity%20between%20each%20other%20and%20to%20the%20domain%20controller%20and%20Active%20Directory.%20To%20not%20complicate%20thing%20further%2C%20we%20assume%20that%20A%2C%20B%20and%20C%20are%20in%20same%20Windows%20domain%20D%20and%20the%20user%20account%20is%20a%20domain%20account%20in%20D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(4)%26nbsp%3B%26nbsp%3B%20The%20user%E2%80%99s%20domain%20account%20must%20NOT%20select%20%E2%80%9CAccount%20is%20sensitive%20and%20cannot%20be%20delegated%E2%80%9D%20in%20its%20Active%20Directory%20properties%20of%20domain%20D.%20Please%20refer%20to%20%5B1%5D%20on%20how%20to%20configure%20this%20on%20Active%20Directory%20machine.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(5)%26nbsp%3B%26nbsp%3B%20The%20service%20account%20under%20which%20the%20SQL%20instance%20is%20running%20must%20be%20%E2%80%9Ctrusted%20for%20delegation%E2%80%9D%2C%20configured%20in%20Active%20Directory.%20If%20the%20service%20is%20running%20as%20%E2%80%9CNT%20AUTHORITYSYSTEM%E2%80%9D%20or%20%E2%80%9CNT%20AUTHORITYNETWORK%20SERVICE%E2%80%9D%2C%20the%20computer%20must%20be%20%E2%80%9Ctrusted%20for%20delegation%E2%80%9D.%20Please%20refer%20to%20%5B1%5D%20on%20how%20to%20configure%20this%20on%20Active%20Directory%20Machine.%20You%20need%20to%20have%20domain%20admin%20privilege%20to%20do%2Fverify%20so.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(6)%26nbsp%3B%26nbsp%3B%20The%20user%20domain%20account%20must%20have%20permission%20to%20access%20both%20SQL%20instances%20from%20C.%20To%20verify%2C%20use%20your%20favorite%20client%20tool%2C%20for%20example%2C%E2%80%9Cosql%20%E2%80%93E%20%E2%80%93S%20SQLA%E2%80%9D%20and%20%E2%80%9Cosql%20%E2%80%93E%20%E2%80%93S%20SQLB%E2%80%9D.%20If%20you%20are%20failing%20for%20whatever%20reason%2C%20please%20refer%20to%20%5B5%5D%5B6%5D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(7)%26nbsp%3B%26nbsp%3B%20If%20the%20SQL%20connections%20are%20to%20use%20TCP%2FIP%20connectivity%2C%20configure%20and%20verify%20that%20SQL%20connections%20from%20C%20to%20A%20and%20A%20to%20B%20are%20using%20Kerberos%20authentication.%20Please%20refer%20to%20%5B2%5D%20on%20how%20to%20configure%20Kerberos%20for%20SQL.%20In%20a%20nutshell%2C%20both%20services%20on%20machine%20A%20and%20B%20need%20to%20have%20a%20SPN%20created%20in%20Active%20Directory%20for%20SQL%20service.%20If%20the%20service%20running%20account%20is%20not%20%E2%80%9CNT%20AUTHORITYSYSTEM%E2%80%9D%2C%20you%20need%20to%20configure%20the%20SPN%20on%20the%20Active%20Directory%20Machine%20with%20domain%20admin%20privileges.%20To%20verify%20that%20every%20hop%20is%20using%20Kerberos%20and%20TCP%20connectivity%2C%20run%20query%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9Cselect%20net_transport%2C%20auth_scheme%20from%20sys.dm_exec_connections%20where%20session_id%3D%40%40spid%E2%80%9D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3Ewhen%20(a)%20connect%20to%20A%20from%20C%20(b)%20connect%20to%20B%20from%20A.%20To%20make%20Kerberos%20work%20for%20both%20hops%20is%20crucial%20and%20some%20time%20it%20might%20not%20be%20very%20straightforward%20on%20what%20goes%20wrong.%20If%20fail%20to%20get%20Kerberos%20to%20work%2C%20please%20(a)%20verify%20If%20the%20SPNs%20are%20configured%20and%20well-formed%20according%20to%20%5B4%5D%3B%20use%20%E2%80%9Csetspn%20%E2%80%93L%20acccoutname%E2%80%9D%20to%20verify%20the%20SPN%20(b)%20verify%20if%20DNS%20reverse%20lookups%20of%20both%20machine%20A%20and%20B%20return%20well-formed%20FQDNs.%20Use%20%E2%80%9Cping%20%E2%80%93a%20machinename%E2%80%9D%20on%20machine%20A%2C%20B%20and%20C%20to%20verify%20DNS%20works%20as%20expected%2C%20i.e.%20returning%20FQDN%3B%20(c)%20make%20sure%20that%20there%20is%20no%20cached%20Kerberos%20ticket%20on%20machine%20A%20and%20C.%20Use%20%E2%80%9Cklist%20purge%E2%80%9D%20to%20purge%20all%20tickets.%20There%20might%20be%20delay%20before%20Windows%20local%20security%20authority%20(LSA)%20requests%20a%20new%20ticket%20from%20Active%20Directory.%20Sometime%2C%20you%20need%20to%20log%20out%20and%20log%20back%20in%20again%20before%20a%20new%20Kerberos%20ticket%20can%20take%20effect.%20For%20more%20Kerberos%20troubleshooting%20techniques%2C%20please%20refer%20to%20%5B3%5D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(8)%26nbsp%3B%26nbsp%3B%20If%20the%20SQL%20connections%20are%20to%20use%20Named%20Pipe%20connectivity%2C%20SQL%20level%20Kerberos%20is%20not%20required%20as%20opposed%20to%20TCP%20connectivity.%20This%20is%20because%20Windows%20named%20pipe%20protocol%20can%20use%20Kerberos%20to%20authenticate%20logon%20user%20under%20the%20cover.%20You%20need%20to%20verify%20that%20both%20machine%20SPNs%20%E2%80%9CHOST%2Fmachinename%E2%80%9D%20and%20%E2%80%9CHOST%2F%20machineFQDN%E2%80%9D%20is%20well-formed%20use%20%E2%80%9Csetspn%20%E2%80%93L%20machinename%E2%80%9D.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E(9)%26nbsp%3B%26nbsp%3B%20Since%20double-hop%20can%20have%20combination%20of%20Named%20pipe%20connectivity%20on%20one%20hop%20and%20TCP%20on%20the%20other%2C%20the%20following%20table%20is%20valid%20configuration%20for%20delegation.%20Run%20query%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%9Cselect%20net_transport%2C%20auth_scheme%20from%20sys.dm_exec_connections%20where%20session_id%3D%40%40spid%E2%80%9D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3Ewhen%20(a)%20connect%20to%20A%20from%20C%20(b)%20connect%20to%20B%20from%20A.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CDIV%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CTABLE%3E%0A%20%20%20%20%3CTBODY%3E%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E%7Bnet%20transport%2C%20auth_scheme%7D%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EC%20to%20A%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3EA%20to%20B%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%20%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E1%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ENP%2C%20NTLM*%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ENP%2C%20NTLM*%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%20%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E2%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ETCP%2C%20Kerberos%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3ENP%2C%20NTLM*%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%20%3CTR%3E%0A%20%20%20%20%20%3CTD%3E%3CBR%20%2F%3E%3CP%3E3%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%20%3CP%3E%3C%2FP%3E%0A%20%20%20%20%20%3C%2FTD%3E%0A%20%20%20%20%20%3CTD%3E%3C%2FTD%3E%0A%20%20%20%20%3C%2FTR%3E%0A%20%20%20%3C%2FTBODY%3E%3C%2FTABLE%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-383138%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Aug%2010%2C%202006%20SQL%20Server%202005%3A%20%E2%80%9CLogin%20failed%20for%20user%20'NT%20AUTHORITYANONYMOUS%20LOGON'%E2%80%9D.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-383138%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerProtocols%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Aug 10, 2006

SQL Server 2005: “Login failed for user 'NT AUTHORITYANONYMOUS LOGON'”.


SQL Server 2000: "Login failed for user "(null)". Reason: Not associated with a trusted SQL Server connection".


The errors listed above is very typical when deploy linked server with delegation. They actually are thrown by the linked server and pass by middle server to the client application. In this post, I will discuss how to properly configure SQL instances and Windows environment in most common scenario and try to make configuration steps as explicit as possible.

By using delegation in distributed query, such as linked server query, the SQL instance obtains impersonated token of the user logon credential to gain access to resources of another SQL instance, the linked server. In delegation setting, the client connection and linked server object are configured to use integrated authentication in SQL Server’s term as opposed to SQL login. Some time integrated authentication also referred as trusted connection or Windows authentication. Linked server login can also use SQL login, but it is not discussed here.

To simplify the discussion, let’s assume two SQL Server instances are installed on machine A and B respectively. Also, let’s assume A is the middle server that has a linked server object configured which points to a SQL instance on machine B. If the client is on machine C different from A, we call it double-hop setting; if the client is collocated with middle server machine A, we call it single-hop setting. In single-hop setting, it is relatively straightforward to configure linked server to work. Believe or not, double-hop setting requires more careful configurations as you will see. This is because in single-hop setting, windows NTLM authentication, which is available in most common setting if all machines are windows, is sufficient for delegation; while in double-hop setting, Kerberos authentication is mandate for flowing user’s credential through machine boundaries from the client to the linked server. It requires windows domain, correct DNS name resolution, proper account setting in both Active Directory and SQL Server.  To make sure Kerberos delegation [1] is correct becomes vital to operate distributed query with delegation. The authentication scheme required by delegation in different setting is illustrated by the following table.
















Authentication scheme


C to A


A to B


Single hop


NTLM or Kerberos


(C is on the same box as A)


NTLM or Kerberos


Double hops


Kerberos


Kerberos

[Create Linked Server Object on Middle Server]

Before getting into details on how to configure other components, since I am talking about delegation in the context of SQL Server distributed query, let’s first give an example on how to configure a linked server object on A and set up its login to use delegation.  To do so, you need the following two steps.

(1) Use sp_addlinkedserver to create a linked server object and name it “LinkedServer” which points to the SQL instance on machine B, SQLB.

“EXEC sp_addlinkedserver @server=’LinkedServer’,

@srvproduct=''”,

@provider='SQLNCLI',

@datasrc=’SQLB’,--the data source

@provstr="Integrated Security=SSPI; "

To verify if the command is executed correctly, run query

“select * from sys.servers where name='LinkedServer'”;

(2) Use sp_addlinkedsrvlogin to configure login to use self-mapping as following

“exec sp_addlinkedsrvlogin ‘LinkedServer’, 'true'”

Step (2) makes middle server A try to use impersonated token of user to authenticate to server B. To verify that the linked server is setup for “self-mapping”, run query

“select uses_self_credential as delegation

from sys.linked_logins as L, sys.servers as S

where S.server_id=L.server_id

and S.name=N'LinkedServer'

The resulting table should show the delegation column is “1”.

[Test Linked Server Query in Single-hop Settting]

Before test-drive a link server query in single-hop setting, you need also make sure that the client user can make direct query to the SQL instances on both A and B. This means that the user account, either windows domain account or a machine account, must have permission to access both SQL instances.

(3) To verify the user domain account has permission to access both SQL instances, use your favorite client tool, for example,“osql –E –S SQLA” and “osql –E –S SQLB”. If you are failing for whatever reason, please refer to [5][6].

(4) To test linked server query, run query at SQLA,

“select * from LinkedServer.master.dbo.sysdatabases”.

[Configure and Test Double-hop Setting]

To deploy delegation based linked server in double-hop setting, the followings need to be configured correctly.

(3)   Kerberos in Windows mandates Windows domain. Therefore the user account needs to be a domain account and middle server and linked server need to join a domain. All machines involved in the delegation, including client machine, middle server and linked server, must have good TCP/IP connectivity between each other and to the domain controller and Active Directory. To not complicate thing further, we assume that A, B and C are in same Windows domain D and the user account is a domain account in D.

(4)   The user’s domain account must NOT select “Account is sensitive and cannot be delegated” in its Active Directory properties of domain D. Please refer to [1] on how to configure this on Active Directory machine.

(5)   The service account under which the SQL instance is running must be “trusted for delegation”, configured in Active Directory. If the service is running as “NT AUTHORITYSYSTEM” or “NT AUTHORITYNETWORK SERVICE”, the computer must be “trusted for delegation”. Please refer to [1] on how to configure this on Active Directory Machine. You need to have domain admin privilege to do/verify so.

(6)   The user domain account must have permission to access both SQL instances from C. To verify, use your favorite client tool, for example,“osql –E –S SQLA” and “osql –E –S SQLB”. If you are failing for whatever reason, please refer to [5][6].

(7)   If the SQL connections are to use TCP/IP connectivity, configure and verify that SQL connections from C to A and A to B are using Kerberos authentication. Please refer to [2] on how to configure Kerberos for SQL. In a nutshell, both services on machine A and B need to have a SPN created in Active Directory for SQL service. If the service running account is not “NT AUTHORITYSYSTEM”, you need to configure the SPN on the Active Directory Machine with domain admin privileges. To verify that every hop is using Kerberos and TCP connectivity, run query

“select net_transport, auth_scheme from sys.dm_exec_connections where session_id=@@spid”

when (a) connect to A from C (b) connect to B from A. To make Kerberos work for both hops is crucial and some time it might not be very straightforward on what goes wrong. If fail to get Kerberos to work, please (a) verify If the SPNs are configured and well-formed according to [4]; use “setspn –L acccoutname” to verify the SPN (b) verify if DNS reverse lookups of both machine A and B return well-formed FQDNs. Use “ping –a machinename” on machine A, B and C to verify DNS works as expected, i.e. returning FQDN; (c) make sure that there is no cached Kerberos ticket on machine A and C. Use “klist purge” to purge all tickets. There might be delay before Windows local security authority (LSA) requests a new ticket from Active Directory. Sometime, you need to log out and log back in again before a new Kerberos ticket can take effect. For more Kerberos troubleshooting techniques, please refer to [3].

(8)   If the SQL connections are to use Named Pipe connectivity, SQL level Kerberos is not required as opposed to TCP connectivity. This is because Windows named pipe protocol can use Kerberos to authenticate logon user under the cover. You need to verify that both machine SPNs “HOST/machinename” and “HOST/ machineFQDN” is well-formed use “setspn –L machinename”.

(9)   Since double-hop can have combination of Named pipe connectivity on one hop and TCP on the other, the following table is valid configuration for delegation. Run query

“select net_transport, auth_scheme from sys.dm_exec_connections where session_id=@@spid”

when (a) connect to A from C (b) connect to B from A.



















{net transport, auth_scheme}


C to A


A to B


1


NP, NTLM*


NP, NTLM*


2


TCP, Kerberos


NP, NTLM*


3