开发者

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

开发者 https://www.devze.com 2023-01-17 12:01 出处:网络
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 t

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.


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.


try this:

Check Internet Connection


I'm not sure whether trying to open a connection to your server and catching an exception without visible feedback will work or not in C#, but are you sure you want to use this method to deal with licensing? It strikes me that not only is it very easy to discover (for example a personal firewall will flag the connection) it's also very easy to defeat.

Additionally, what happens if the user's computer isn't connected to the internet? Unlikely, I know, but it can happen, and your licensing scheme is defeated with no conscious effort on the user's part.


you can also try this

C# - Check internet connection

0

精彩评论

暂无评论...
验证码 换一张
取 消