Uzytkownik "Paul Clement said:
¤ I am accessing an Access database with User groups/accounts set up, is
there
¤ any way for me to determine which groups indvidual accounts are a
member of
¤ from my .net application.
¤ (...)
I don't believe you can use Access SQL DDL so you will probably need to
use ADOX (Microsoft ADO Ext
2.x for DDL and Security):
Another option is use system tables or queries. In Access membership of
users is preserved in mdw file, that is specific access database file.
There is query: MSysUserMemberships (among others) that contains
information you want. Example of use;
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
namespace TestMemberOfGroupMdwCsharp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string user = "Grzegorz";
Test t = new Test(@"E:\Development\Test.mdw");
try
{
ArrayList groups = t.Groups(user);
System.Console.WriteLine(user + "'s groups:");
foreach(string gr in groups)
System.Console.WriteLine(gr);
}
catch(OleDbException ex)
{
System.Console.WriteLine(ex.Message);
}
System.Console.ReadLine();
}
}
class Test
{
OleDbConnection con;
OleDbCommand grC;
public Test(string mdwFile)
{
//path, user and password to any mdw file,
//it can be also mdwFile, but in the situation
//true password and user id is needed
string systemDb = @"C:\Windows\System32\System.mdw";
string user = "Admin";
string pass = "";
con = new OleDbConnection(
";Provider=Microsoft.Jet.OLEDB.4.0" +
";Data Source=" + mdwFile +
";Jet OLEDB:System database=" + systemDb +
";Password=" + pass + ";User ID=" + user);
//reference to access system database query
grC = new OleDbCommand("MSysUserMemberships", con);
grC.CommandType = CommandType.StoredProcedure;
grC.Parameters.Add("@UserName", OleDbType.VarChar);
}
public ArrayList Groups(string userName)
{
ArrayList usGroups = new ArrayList();
con.Open();
try
{
grC.Parameters["@UserName"].Value = userName;
OleDbDataReader dr = grC.ExecuteReader();
while(dr.Read())
usGroups.Add(dr.GetString(0));
}
finally
{
con.Close();
}
return usGroups;
}
}
}
Of course using system tables/queries is less recommended - it is some
undocumented feature and in future version of Access it can be changed.
I hope it helps.
Grzegorz