I know this website is for DBAs, but I thought I'd share with you all what I've found so far. I'm pursuing using SMO, primarily because it looks like it will give me what I need for databases, not just at the server level. I've found 2 links that are helpful from Microsoft's MSDN website.Managing Uses, Roles, and Logins and Create a Visual C# SMO Project in Visual Studio .NET. You need to look at those 2 links. After you've done that I'd like to share with you how I've changed the code for C# in the first link. Here it is:
using System;
using System.Data;
using Microsoft.SqlServer.Management.Smo;
namespace SmoListLogins
{
class Program
{
static void Main(string[] args)
{
ListLogins();
}
static private void ListLogins()
{
//Server srv = new Server(); //local database - i.e.: localhost
Server srv = new Server("YOURDATABASEINSTANCE");
//Iterate through each database and display.
foreach (Database db in srv.Databases)
{
Console.WriteLine("========");
Console.WriteLine("Login Mappings for the database: " + db.Name);
Console.WriteLine(" ");
//Run the EnumLoginMappings method and return details of database user-login mappings to a DataTable object variable.
DataTable d;
try
{
d = db.EnumLoginMappings();
//Display the mapping information.
foreach (DataRow r in d.Rows)
{
foreach (DataColumn c in r.Table.Columns)
{
Console.WriteLine(c.ColumnName + " = " + r[c]);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error processing database: {db.Name}");
Console.WriteLine($"Error: {ex.Message}");
Console.WriteLine();
}
}
}
}
} Kindest Regards, Rod Connect with me on LinkedIn.