TWINXBASE Service


How it works:

This service scans in a directory (C:\FILESERVICE\INBOX) by using FileWatcher component (.NET) (not really scans.. check for created files) when a file arrives, then the service will check the extension of the file, if the file has the extension .DBX then it will read the contents of the file and communicate with the database(C:\FILESERVICE\DB\MyDB.mdb) and insert / update / delete the records in the database - table.

Then the file will be moved to the subdirectory \BACKUP. When an error occured the error will be logged in the EventLog.

If an other FILE arrives in the inbox , not an DBX file it will move it to the subdir \UNKNOWN.

So if you look at the code, you can easy make the service to use with other kind of files and you can make an application (class) that handle those files.

Example extension .MAIL could be used to send mails by using my code in "C# MAIL CONSOLE"
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=97&lngWId=10

FIRST RUN 

If the service is running then the first time it will check if the directory's exists on the C:\ drive.
if not, it will be created, the directory's are:

C:\FILESERVICE\DB
C:\FILESERVICE\INBOX
C:\FILESERVICE\INBOX\BACKUP
C:\FILESERVICE\INBOX\UNKNOWN

In the zip file you can find 2 examples for database use, called USERS.DBX and ARTICLES.DBX If you want to view those files open it with notepad. the records are comma separated.

Next you have to do is copy the Access dababase file included in the zip file and copy it to the
C:\FILESERVICE\DB directory.

Then you can put a example of the file .DBX in the inbox dir, and the service will handle the file.
Open then the database file and check the records that are inserted/updated / deleted.

INSTALL SERVICE

First compile the application so you will have an executable (exe)
for the Visual Studio users , go to START -> Microsoft VS.NET -> VS.NET Tools -> VS.NET Command Prompt.

You will see a command box (console) then go to the directory where the exe is. then in that directory type : 

> InstallUtil MyFileService.exe
This will install the service Once it correctly installed you can start the service by typing :>

> NET START TWINXBASE
Or you can go to Services in Configuration, look for the new service, start it.

To Remove the service, stop the service and type than :
> InstallUtil /u MyFileService.exe


Remark : this is just a small example..

I will try to make the service later for reading XML files for database use and others. But now you have an idea how to create a service and more..


Similar Articles