Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:52:50+00:00 2026-06-11T12:52:50+00:00

I have a mysql database with data like username, date and share path. the

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:52:51+00:00Added an answer on June 11, 2026 at 12:52 pm

    Re-write your query to fetch the specific rows like this

    "SELECT expDate, user, sfolder FROM  permuser WHERE expDate=GetDate()";
    

    I have taken your code and re-adjusted it below.

    try
    {
        string MyConString =
            "SERVER=localhost;" +
            "DATABASE=permdata;" +
            "UID=user;" +
            "PASSWORD=pass;";
    
        DataSet dataSet = new DataSet(); // Set a new DataSet instance
        string sql = "SELECT expDate, user, sfolder FROM  permuser WHERE expDate=GetDate()"
    
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand cmdSel = new MySqlCommand(sql, connection);
        new SqlDataAdapter(cmdSel).Fill(dataSet, "permuser"); // passing the command into the DataAdapter
    
    
        foreach (DataRow row in dataSet.Tables["permuser"].Rows)
            {
                //*get user and share path
                row["user"]; //User rows
                 row["sfolder"]; //sfolder rows
                *myDirectorySecurity.RemoveAccessRule (user/share path)
            }
    
        connection.Close();
        connection.Dispose();
    }
    
    catch (MySqlException ex)
    {
        MessageBox.Show(ex.Message);
        Close();
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database which contains data i would like to populate into
I have a script that automatically populates a mysql database with data every hour.
I have following query and data saved in a MySQL database with a timestamp
I have a simple php page that displays data from a mysql database. I
If i already have record with the exact same data in mysql database i
Hi i have a small query which takes data from one mysql database and
I have an issue. I am getting data from a MySQL database, and make
In my SQL Server database schema I have a data table with a date
I have mysql database like this id | code 1 | bok-1 2 |
I have a database that contains user details including sensitive data. They're not as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.