Linked Questions

Popular Questions

I have the below python script that queries for list of SQL logins. I already had a few SQL logins that are showing up. However after I created a SQL test login it's not showing up when I run my script. Though it does show up when I run the same query on SQL Management Studio.. any thoughts?

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

Related Questions