microsoft / microsoft/sqlmanagementobjects
Login.EnumDatabaseMappings returns null unexpectedly
未关闭
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 143
- 派生
- 28
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。