Posts: 25
Threads: 6
Joined: Mar 2013
Reputation:
0
Hello guys,
I want my software that it will contain a server status dialog. When a user will click on the server status then a dialog will open in which they will be able to see if the MySQL server with this software in online or offline.
I need a code that will open a db connection and if connection open the show a circle with green color and say green color Online and if db connection timeout then they will get a the circle red and red Offline text and this will happen if their internet connection is not available....and if their internet connection available but my MySQL server is down then they will get a yellow color on the circle and will say server offline...
Please provide me the code by which I can do this...
Thanks in advance.....
Posts: 25
Threads: 6
Joined: Mar 2013
Reputation:
0
I need to get the server status my db connection not by ping method.
Another:
I need another solution on this that how can I ping any server and if ping successful then circle will be green and if ping timed out then circle will be yellow and if destination unreachable then the circle will be red and if the domain or ip doesn't exist then it will say plzzz enter a valid ip or domain.....
Posts: 31
Threads: 2
Joined: Oct 2012
Reputation:
0
Checking if the computer is conected to the internet:
[code2=vbnet]If My.Computer.Network.IsAvailable = True Then
MsgBox("Your computer is conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Information")
Else
MsgBox("Your computer is not conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical, "Information")
End If[/code2]
Pinging a host:
First import System.Net and System.Net.NetworkInformation:
[code2=vbnet]Imports System.Net, System.Net.NetworkInformation[/code2]
Then ping with the folowing code:
[code2=vbnet]Sub Ping()
Dim ping As New Ping()
Dim reply As PingReply
Dim _byte As Byte() = BitConverter.GetBytes(32)
Try
reply = ping.Send(Host, 1000, _byte)
Select Case reply.Status
Case IPStatus.Success
' code for succesfull ping
Case IPStatus.TimedOut
' code for ping timeout
Case IPStatus.BadDestination
'code for bad adress
Case Else
'code for other ocurences
' you can put a MsgBox that will say that something else happened
'MsgBox("Please check code", MsgBoxStyle.Exclamation, "Ping Status")
End Select
Catch pex As PingException
MsBox(pex.ToString)
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString)
End Try[/code2]
Now before you reply to this post saying that the code above does not work replace "Host" with the actual ip of the web site.
For the third problem , checking if MySql server is online or not, that is also simple because usualy MySql has a default port number and its just a case of connecting a TcpClient to that ip and port and if it connects it means it is online.
Here are the steps to do just that:
First , just as above import System.Net And System.Net.Sockets(i'm not going to show how to do it again)
Second Use this code snippet:
[code2=vbnet]Private Sub CheckServerStatus()
Try
Dim TcpCl As New TcpClient
Dim IpEP As New IPEndPoint(IPAddress.Parse("IP"), 3306) 'if i'm not mistaking 3306 is the default port for Mysql Server
TcpCl.Connect(IpEP)
If TcpCl.Connected Then
'code for serve online
TcpCl.Close()
End If
Catch ex As Exception
'code for server offline
End Try
End Sub[/code2]
Replace "IP" with the ip of the server you are trying to connect. REMEMBER THE "IP" HAS TO BE A STRING !!!
Sssssssssoftware developer...
Posts: 25
Threads: 6
Joined: Mar 2013
Reputation:
0
bro i already told in my post that i don't need the ping method for my db server status....i need the server status form to open a db connection and if failed then make a circle yellow and if the computer is not connected with the internet then it will make the circle red and if db connection ok then it will make the circle green...
i could have used the ping method but my server allow no pinging to it.....
Posts: 31
Threads: 2
Joined: Oct 2012
Reputation:
0
Read the third block of code , it has nothing to do with pinging a host , it's a simple TcpClient that conects to the web site on a spcific IP and PORT number
Sssssssssoftware developer...
Posts: 25
Threads: 6
Joined: Mar 2013
Reputation:
0
thanks bro...
your code worked successfully but can i add another status on the code...like
now i am getting a status for server online and another status for server offline and also for computer in n0t connected with the internet....
can u please provide me the code to get these three status...
Thanks in advance....