locked
about filesystemwatcher RRS feed

  • Question

  •  

    Hi,

     

    Can filesystemwatcher monitor on a specific table only in a database? becoz i want to prompt the user if there's a new updated or new item in my database and and choose if he/she want to refresh the datagridview.

     

     

     

    Regards

    Monday, September 10, 2007 5:34 AM

Answers

  • Hi Pinoyz,

     

    The FileSystemWatcher class is used to monitor file system changes inside a directory, the limit is that it can be applied to a specific file.

     

    1. To Access or SQL Server database, a table isn't an independent file but integrated into a database file, so you can't use the FileSystemWatcher to monitor a table but can monitor the database file.

    e.g.

    Code Snippet

    Dim watcher As FileSystemWatcher = New FileSystemWatcher
    watcher.Path 
    = @"\\ServerName\Share"

    watcher.Filter = "myDatabase.mdb"

     

    2. To FoxPro database, table files ( *.dbf ) and database file are independent files, so you can use the FileSystemWatcher to monitor a table file.

     

    The following is MSDN document:

    FileSystemWatcher Class

    Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

    Remarks

    Use FileSystemWatcher to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory.

     

     

    Suggestion: Post such issues about .NET Class usage at .NET Base Class Library forum,  you can get better and quicker responses.

     

    Thanks,

    Martin

    Thursday, September 13, 2007 12:11 PM
  • Hi Pinoyz,

     

    I was thinking that maybe you can set up your own little system

    Maybe you can use the record changing events to write to a log file.

    It would just have to be a text file that you append with the time and the change information

    then your filewatcher can monitor the log file for changes

    If there are changes then you can notify the user

     

    You could keep track of who made the changes, what computer, the time, and what they did

    you could use this to notify the administrator as well if there are changes made that they need to keep track of

     

    if you needed it to be more secure then you could use a database table for this instead of a text file

     

    Just a thought

    Hope this helps give you some ideas

    Jeff

    Thursday, September 13, 2007 3:10 PM
  • Pinoyz,

     

    Here is what i mean

     

    First you create a log file (text file) that will be a log for the ticket table only

    Now when a user modifies the ticket table by any events that cause a change you use the event to append text to the log file. 

    Depending on the event where the changes were made you would use this to determine what you would write to the file

    Let's say that the user deleted a record

    In that event you would append to the file 

    Date and time, User, deleted ticket record

    The file system watcher would then notify the other user that a change has been made to the log file (not the database)

    and you could retrieve the last log entry and show it to the user

     

    Ofcourse you could modify this however you wanted to

     

    The whole idea is to watch the file that you are controlling (log file)

    Do this make more sense?

     

    Jeff

    Friday, September 14, 2007 2:55 AM
  • Hi Pinoyz,

     

    Jeff came up with a good idea. You create a log file (.txt), when someone operates database (such as insert/update/delete records), you can write relevant messages ( who , what , when etc.) into the log file. Then you only need to use the FileSystemWatcher to monitor the log file. The following code can be placed at where did the database operations.

     

    If you only want to monitor the ticket table, you only need to place the following code at where did the ticket table operations in order to only record the log about this table, then you use the FileSystemWatcher to monitor the log file.

     

    "but there's nothing changes in a ticket table only on login table and still prompt the user there's an updated file."

    -> If no any operation which changes the ticket table, you don't need to record the log into the log file.

     

    This approach is better and easier than using Trigger.

     

    Code Snippet

    Imports System.IO

     

        Sub Main()

     

            Dim log As StreamWriter

            If Not File.Exists("D:\logfile.txt") Then

                log = New StreamWriter("D:\logfile.txt")

            Else

                log = File.AppendText("D:\logfile.txt")

            End If

     

            'Assume someone insert/update/delete the TableA in your database here

            'e.g. insert TableA Values("value1","value2","value3")

            'then you can write the message to the log file like this:

            Dim strLogText As String = New String("   Certain User inserts values to the TableA.")

            log.Write(DateTime.Now)

            log.Write(strLogText)

            log.WriteLine()

            log.Close()

     

        End Sub

     

     

    Friday, September 14, 2007 3:07 AM

All replies

  •  

    Bump
    Tuesday, September 11, 2007 12:04 AM
  • Please allow me to bump it once too.

    Thursday, September 13, 2007 12:09 PM
  • Hi Pinoyz,

     

    The FileSystemWatcher class is used to monitor file system changes inside a directory, the limit is that it can be applied to a specific file.

     

    1. To Access or SQL Server database, a table isn't an independent file but integrated into a database file, so you can't use the FileSystemWatcher to monitor a table but can monitor the database file.

    e.g.

    Code Snippet

    Dim watcher As FileSystemWatcher = New FileSystemWatcher
    watcher.Path 
    = @"\\ServerName\Share"

    watcher.Filter = "myDatabase.mdb"

     

    2. To FoxPro database, table files ( *.dbf ) and database file are independent files, so you can use the FileSystemWatcher to monitor a table file.

     

    The following is MSDN document:

    FileSystemWatcher Class

    Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

    Remarks

    Use FileSystemWatcher to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory.

     

     

    Suggestion: Post such issues about .NET Class usage at .NET Base Class Library forum,  you can get better and quicker responses.

     

    Thanks,

    Martin

    Thursday, September 13, 2007 12:11 PM
  • OIC, I thougt it can be used.... i'm having difficulties about prompting the user if there's any update, insert or delete in a table. if there's some one login or logout in my application the user will prompt there an updated ticket or something... And also i'm having trouble about trigger.... anyway thanks Martin...

    Thursday, September 13, 2007 1:56 PM
  • Hi Pinoyz,

     

    I was thinking that maybe you can set up your own little system

    Maybe you can use the record changing events to write to a log file.

    It would just have to be a text file that you append with the time and the change information

    then your filewatcher can monitor the log file for changes

    If there are changes then you can notify the user

     

    You could keep track of who made the changes, what computer, the time, and what they did

    you could use this to notify the administrator as well if there are changes made that they need to keep track of

     

    if you needed it to be more secure then you could use a database table for this instead of a text file

     

    Just a thought

    Hope this helps give you some ideas

    Jeff

    Thursday, September 13, 2007 3:10 PM
  • Using FileSystemWatcher only monitor's File, any changes occured in a database will notify the user that there's a new updated file, for example i log to my system and of course there's a changes in a table because of time of login. but i want only is to monitor the ticket table. Once theres changes in the table it will automatically prompt the user there's a new updated file but there's nothing changes in a ticket table only on login table and still prompt the user there's an updated file. And also when i add table to monitor or to view changes that made, It still's the same.

     

    Friday, September 14, 2007 2:27 AM
  • Pinoyz,

     

    Here is what i mean

     

    First you create a log file (text file) that will be a log for the ticket table only

    Now when a user modifies the ticket table by any events that cause a change you use the event to append text to the log file. 

    Depending on the event where the changes were made you would use this to determine what you would write to the file

    Let's say that the user deleted a record

    In that event you would append to the file 

    Date and time, User, deleted ticket record

    The file system watcher would then notify the other user that a change has been made to the log file (not the database)

    and you could retrieve the last log entry and show it to the user

     

    Ofcourse you could modify this however you wanted to

     

    The whole idea is to watch the file that you are controlling (log file)

    Do this make more sense?

     

    Jeff

    Friday, September 14, 2007 2:55 AM
  • Hi Pinoyz,

     

    Jeff came up with a good idea. You create a log file (.txt), when someone operates database (such as insert/update/delete records), you can write relevant messages ( who , what , when etc.) into the log file. Then you only need to use the FileSystemWatcher to monitor the log file. The following code can be placed at where did the database operations.

     

    If you only want to monitor the ticket table, you only need to place the following code at where did the ticket table operations in order to only record the log about this table, then you use the FileSystemWatcher to monitor the log file.

     

    "but there's nothing changes in a ticket table only on login table and still prompt the user there's an updated file."

    -> If no any operation which changes the ticket table, you don't need to record the log into the log file.

     

    This approach is better and easier than using Trigger.

     

    Code Snippet

    Imports System.IO

     

        Sub Main()

     

            Dim log As StreamWriter

            If Not File.Exists("D:\logfile.txt") Then

                log = New StreamWriter("D:\logfile.txt")

            Else

                log = File.AppendText("D:\logfile.txt")

            End If

     

            'Assume someone insert/update/delete the TableA in your database here

            'e.g. insert TableA Values("value1","value2","value3")

            'then you can write the message to the log file like this:

            Dim strLogText As String = New String("   Certain User inserts values to the TableA.")

            log.Write(DateTime.Now)

            log.Write(strLogText)

            log.WriteLine()

            log.Close()

     

        End Sub

     

     

    Friday, September 14, 2007 3:07 AM
  • oic, i think i overthink of it that's why simple things make more complicated ^ ^. And i'm gonna make a shared folder in a server where my logfile is.

     

    @Jeff,

     

    Join us in SQL warrior Here's the link http://sqlwarrior.freehostia.com/forum/index.php

     

     

    Thanks Again,

    Christian

     

    Friday, September 14, 2007 5:25 AM
  • I tried to go to the site before and it won't come up

    I have tried about 5 times now and the page just will not load

     

    I guess i will try again later

    Friday, September 14, 2007 1:59 PM