Subject Re: How can I check using C# if firebird is running?
Author clemenslinders
On a different forum Carlos gave me a answer.

For other people that experience the same problem I would like to
explain it a bit further.

In order to find out if there is any problem reading the database
(is done during the filling of the dataset) I now use:

try
{
TheDataAdapter.Fill(TheDataSet);
}
catch
{
if (File.Exists
(TheDataAdapter.SelectCommand.Connection.Database))
{
try
{
ServiceController FireBirdService = new ServiceController
("FirebirdGuardianDefaultInstance");
FireBirdService.Start();
DeDataAdapter.Fill(TheDataSet);
}
catch
{
MessageBox.Show(ADataBaseOpenIngErrorProbablyServer);
}
}
else
{
MessageBox.Show(ADataBaseHasBeenRemovedError);
}
}

This works perfectly. I know some people disagree on checking the
existens of the file as the user doesn't need to know what file
actually is de database file. But regardless of that any stupid
client is capable of removing just about any file. And when the
customer calls and says I get a DataBase has been deleted error,
than you know immediately what has happened.

As is also mentioned in the dotnetfirebird.org, the starting up of
the service will probably not work if Firebird is located on a
server.

One last thing I need to mention for novice users. When you search
c# help for ServiceController you will see
it's namespace is System.ServiceProcess. So you might expect that
using System.ServiceProcess will enable you to use ServiceController
(or directly System.ServiceProcess.ServiceController) but
unfortunately that is not the case. You have to drop a
ServiceController from the Toolbox on your screen.

I hope this is usefull for any future readers.

Should I indeed get the idea that the shutting down of the service
is a Beta issue, than I will try to contact the developers. But you
should know that I have the habbit of sometimes opening Visual
Studio 4 or 5 times (I have two big screens). Usually this works
fine, but if I leave my computer running these 5 VS's unatended for
several hours than sometimes strange things happen. And under these
conditions it happend twaice that after shutting down and restarting
the computer that the service had stopped. So personally I blame it
to the fact that I opened VS so many times. I am happy now that I
know how to check if the service is running and that I'm able to
start it up (for a local version). As some clients will always be
idiots, there will always be clients that, with the idea of tuning
their PC, will shut down the service themselves.


Kind regards,



Clemens Linders
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@...> wrote:
>
> --- In firebird-support@yahoogroups.com, "clemenslinders"
> <clemenslinders@> wrote:
> >
> > LS,
> >
> > I noticed a few times that that the firebird service may be down.
>
> Why would it be down? Is it crashing or do you have some hardware
or
> network issue?
>
> > My
> > application will than ofcourse crash.
>
> Your connection libraries will probably throw an exception, and if
you
> do not handle that exception, then yes it will crash. Your
application
> does not have to crash though, it could do a friendly notification
to
> the user that the database is down of whatever the exception says.
>
> >
> > Ofcourse using VS 2005 C# I can use a TRY CATCH and if the
database
> > files exists than it remains the obvious that firebird must be
down.
> > But some kind of Firebird check is more elegant and possibly
there is
> > a way to start up the firebird service.
>
> Why do a file exists check? My users don't even get file system
access
> to the database, and nor should yours if you care for security.
>
> When you attempt to establish a connection, you will receive an
> exception if the service is not running. If you try and run a query
> but the service is not running, you will get an exception.
>
> I do not know C#, but I would be extremely surprised if there is no
> global exception handler you could not use to react appropriately
to
> an unavailable service.
>
> You need to consider also that if it is not stopped by user
> interaction, the service should never be down. If it does just go
> down, you need to investigate why, because that is not normal.
>
> As you are a beta tester, you should also try to determine whether
> your issue is a consequence of any potential bug in Firebird 2.
>