通过pyodbc查询时未显示新创建的SQL用户

时间:2019-02-11 21:02:01

标签: python sql-server pyodbc

我有下面的python脚本,用于查询SQL登录名列表。我已经显示了一些SQL登录名。但是,在创建SQL测试登录名后,运行脚本时不会显示该登录名。虽然当我在SQL Management Studio上运行相同的查询时确实显示了。.有什么想法吗?

conn = pyodbc.connect("DRIVER={SQL Server};SERVER={hostname}; \
   UID={sa};PWD={password};")

command = ''.join(['SELECT pr.principal_id, pr.name, pr.type_desc,', 
    'pe.state_desc, pe.permission_name FROM sys.server_principals AS pr ', 
    'JOIN sys.server_permissions AS pe ON pe.grantee_principal_id = pr.principal_id ',
    'WHERE pr.type=\'S\' AND pr.is_disabled=0;'
])
rows = conn.execute(command)
for row in rows:
     print row.name, row.permission_name

0 个答案:

没有答案