I have a mysql database with data like username, date and share path.
the app can give r/w permit to a share path to specific user with an expiration date and all that data is inserted in mysql.
i want to be able to read row by row like a while, for each loop to read every row and if find a row with the exp date = today get the user and share path and remove the permits.
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();
}
any idea would be great, thanks
i end up doing this, thanks Michael..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);
}
Re-write your query to fetch the specific rows like this
I have taken your code and re-adjusted it below.
Taking a proper look at the code above, you would discover that I have used a DataSet and eliminated the SqlReader because I find DataSet much easier and safe.