Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if internet connectivity available or not in C#

Tags:

c#

I have developed a software for a company. For some kind of licensing purpose i am using a remote database to allow/disallow usage of the software. This task is applied every time the user logs into the software. If the internet connection does not exist or the query to the remote database fails, the user gets an error and he can not log into the software and shows the remote database http address (which i dont want him to see, if he carefully read the error)

What i want to know is any way of doing the same procedure, but if the remote database query fails or internet connection is not available, it should bypass the check for the time being, and upon next login try, same procedure is followed. So that my client should not know about this licensing stuff.

How to check the internet connectivity (LAN, WiFi, Dialup or whatever the user is using) before creating a query to the remote database.

Proposed methods:

  1. Ping my remote database server IP.

  2. This Question by Michel

Regarding results what i achieved from Michel' question is no stable solution.

like image 664
booota Avatar asked Jan 22 '23 10:01

booota


1 Answers

Why not just try to perform a very cheap query on the database? Indeed, you could create a stored procedure for exactly this purpose - it might even give some version information back, etc.

After all, the important thing isn't whether a ping works, or whether the client can go to other machines: the important thing is whether you can talk to the database or not. So test exactly that.

As for what error message is presented to the user - surely that's under your control, so make sure you give appropriate information.

like image 120
Jon Skeet Avatar answered Feb 24 '23 00:02

Jon Skeet