Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Login.EnumDatabaseMappings returns null unexpectedly

未關閉
#37 0 則留言 1 個 reaction 已指派 1 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

這個 Issue 還沒有評估資料。

描述

Create a login on the server using SQL Authentication
Create a user in a database for that login
call Login.EnumDatabaseMappings.
It should return a collection with 1 entry at least, but sometimes it returns null.

var login = new Login(db.Parent, GenerateUniqueSmoObjectName("login"))
                {
                    LoginType = LoginType.SqlLogin,
                    
                };
                var pwd = Guid.NewGuid().ToString();
                login.Create(pwd);
                var credential = new Credential(db.Parent, GenerateUniqueSmoObjectName("login")) { Identity = "someidentity" };
                var dbUser = db.CreateUser("loginUser", login.Name);
// this assert can fail
                Assert.That(login.EnumDatabaseMappings()?.Select(m => m.DBName), Has.Member(db.Name), "login.EnumDatabaseMappings");

This is the query:

create table #loginmappings( LoginName sysname NULL, DBName sysname NULL, UserName sysname NULL, AliasName sysname NULL )
declare @db_name nvarchar(512)
declare crs cursor local fast_forward
	

 
	for ( select name from sys.databases where 1 = has_dbaccess(name)) 
			


open crs 
fetch crs into @db_name
while @@fetch_status >= 0 
begin 
	set @db_name = quotename(@db_name)
		

 
	exec('use ' + @db_name + ' INSERT #loginmappings select suser_sname(u.sid), db_name(), u.name, null from sys.database_principals AS u where suser_sname(u.sid) is not null')
			

 
	fetch crs into @db_name
end 
close crs
deallocate crs
		


SELECT
logmap.LoginName AS [LoginName],
logmap.DBName AS [DBName],
logmap.UserName AS [UserName]
FROM
sys.server_principals AS log
INNER JOIN #loginmappings AS logmap ON logmap.LoginName=log.name
WHERE
(log.type in ('U', 'G', 'S', 'C', 'K', 'E', 'X') AND log.principal_id not between 101 and 255 AND log.name <> N'##MS_AgentSigningCertificate##')and(log.name='login_Login_apis_work_correctly824ead3d-8f57-4c48-9f19-59c8dd560808')

drop table #loginmappings
	
主要語言
C#
星號
143
分支
28
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/sqlmanagementobjects 的其他 Issue

查看 microsoft/sqlmanagementobjects 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。