我有一个 mysql 数据库,其中包含用户名、日期和共享路径等数据。
该应用程序可以向具有到期日期的特定用户授予共享路径的读/写许可,并且所有这些数据都插入到 mysql 中。
我希望能够像一段时间一样逐行读取,让每个循环读取每一行,如果找到具有 exp date = today 的行,则获取用户并共享路径并删除许可。
try
{
string MyConString =
"SERVER=localhost;" +
"DATABASE=permdata;" +
"UID=user;" +
"PASSWORD=pass;";
string sql = "SELECT expDate, user, sfolder FROM permuser";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand cmdSel = new MySqlCommand(sql, connection);
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
MySqlDataReader dr = cmdSel.ExecuteReader();
while (dr.Read())
{
foreach ( *row that exp. date = today)
{
*get user and share path
*myDirectorySecurity.RemoveAccessRule (user/share path)
}
}
connection.Close();
connection.Dispose();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
Close();
}
任何想法都会很棒,谢谢
我最终这样做了,谢谢迈克尔..1
try
{
string MyConString =
"SERVER=localhost;" +
"DATABASE=permdata;" +
"UID=user;" +
"PASSWORD=pass;";
DataSet dataSet = new DataSet();
string sql = "SELECT key, fdate, user, perm, sfolder FROM permuser WHERE fdate=CURDATE()";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand cmdSel = new MySqlCommand(sql, connection);
new MySqlDataAdapter(cmdSel).Fill(dataSet, "permuser");
foreach (DataRow row in dataSet.Tables["permuser"].Rows)
{
string fuser = row["user"].ToString();
string pathtxt = row["sfolder"].ToString();
DirectoryInfo myDirectoryInfo = new DirectoryInfo(pathtxt);
DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" + fuser;
myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule(User, FileSystemRights.Write | FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow));
myDirectoryInfo.SetAccessControl(myDirectorySecurity);
}
connection.Close();
connection.Dispose();
}
catch (MySqlException ex)
{
Console.WriteLine(ex.Message);
Environment.Exit(0);
}