|
Try to Use "FlowLayOutPanel"
ToolBox ->Container
|
|
|
|
|
Hi.
I've found a ping example which I've been tryig do expand with a database etc, but I have one question:
When using the code below, I cant seem to get it to continue pinging - it just stops when "a host is not there".
Can anyone see how I can make it continue and just add the data "DNS Error" to the database?
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
namespace printHosts
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
}
SqlConnection oconn;
SqlCommand ocomm;
string sSql = "";
int ID = 0;
string address = "";
oconn = new SqlConnection(@"server=server;database=database;user id=user; password=password");
sSql = "SELECT hostname FROM Hostinfo";
ocomm = new SqlCommand(sSql);
SqlDataAdapter myapdater = new SqlDataAdapter(sSql, oconn);
DataSet ds = new DataSet("Hostinfo");
DataTable dataTable = ds.Tables["Hostinfo"];
myapdater.Fill(ds, "Hostinfo");
foreach (DataRow row in ds.Tables[0].Rows)
{
address = row["hostname"].ToString();
Console.WriteLine(address);
try
{
sSql = "SELECT COUNT(*) FROM Hostinfo WHERE hostname ='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
if (Convert.ToInt32(ocomm.ExecuteScalar()) == 0)
{
sSql = "INSERT INTO Hostinfo (hostname, currentPingTime) values "
+ "('" + row["hostname"].ToString() + "', '"
+ DateTime.Now + "', '"
+ "')";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
}
else
{
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
sSql = "UPDATE Hostinfo SET "
+ "', LastPingTime ='" + ""
+ " WHERE id=" + ID;
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
catch
{
oconn.Open();
DateTime LastUpdatedPingTime = DateTime.Now;
sSql = "SELECT COUNT(*) FROM Hostinfo WHERE hostname ='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
if (Convert.ToInt32(ocomm.ExecuteScalar()) == 0)
{
sSql = "INSERT INTO Hostinfo (hostname, currentPingTime, repley) values"
+ "('" + row["hostname"].ToString() + "', '"
+ DateTime.Now + "', '"
+ address + "', '"
+ "')";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
}
else
{
sSql = "SELECT ID FROM Hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ID = Convert.ToInt32(ocomm.ExecuteScalar());
sSql = "UPDATE Hostinfo SET "
+ " currentPingTime ='" + DateTime.Now
+ "', repley ='" + address
+ "' WHERE id= '" + ID + "'"; ;
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
if (IsOffline())
{
return;
}
IPAddress ip = null;
try
{
ip = Dns.GetHostEntry(address).AddressList[0];
}
catch (System.Net.Sockets.SocketException ex)
{
Console.WriteLine("DNS Error: {0}", ex.Message);
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
return;
}
//Console.WriteLine("Pinging {0} [{1}] with 32 bytes of data:", address, ip.ToString());
Console.WriteLine();
Thread pingThread = new Thread(new ParameterizedThreadStart(StartPing));
pingThread.Start(ip);
pingThread.Join();
}
}
[Flags]
enum ConnectionState : int
{
INTERNET_CONNECTION_MODEM = 0x1,
INTERNET_CONNECTION_LAN = 0x2,
INTERNET_CONNECTION_PROXY = 0x4,
INTERNET_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
}
[DllImport("wininet", CharSet = CharSet.Auto)]
static extern bool InternetGetConnectedState(ref ConnectionState lpdwFlags, int dwReserved);
static bool IsOffline()
{
ConnectionState state = 0;
InternetGetConnectedState(ref state, 0);
if (((int)ConnectionState.INTERNET_CONNECTION_OFFLINE & (int)state) != 0)
{
return true;
}
return false;
}
static void StartPing(object argument)
{
SqlConnection oconn;
SqlCommand ocomm;
string sSql = "";
int ID = 0;
string address = "";
try
{
oconn = new SqlConnection("server=sqlserver;database=audit_data;uid=user;pwd=password;");
oconn.Open();
sSql = "SELECT Hostname from hostinfo WHERE HostName='" + address + "'";
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
{
ocomm = new SqlCommand(sSql, oconn);
ocomm.ExecuteNonQuery();
}
oconn.Close();
}
catch (Exception e)
{
}
IPAddress ip = (IPAddress)argument;
//set options ttl=128 and no fragmentation
PingOptions options = new PingOptions(128, true);
//create a Ping object
Ping ping = new Ping();
//32 empty bytes buffer
byte[] data = new byte[32];
int received = 0;
List<long> responseTimes = new List<long>();
//ping 4 times
for (int i = 0; i < 1; i++)
{
PingReply reply = ping.Send(ip, 1000, data, options);
if (reply != null)
{
switch (reply.Status)
{
case IPStatus.Success:
Console.WriteLine("Reply from {0}",
reply.Address, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl);
received++;
responseTimes.Add(reply.RoundtripTime);
break;
case IPStatus.TimedOut:
Console.WriteLine("Request timed out.");
break;
default:
Console.WriteLine("Ping failed {0}", reply.Status.ToString());
break;
}
}
else
{
Console.WriteLine("Ping failed for an unknown reason");
}
}
}
}
}
Thanks Jan.
|
|
|
|
|
While put Code please use proper format [ InlineCode ] and [Code Block]
that will be more understandable by all.
Thanks
|
|
|
|
|
Member 1541838 wrote: When using the code below, I cant seem to get it to continue pinging - it just stops when "a host is not there".
Member 1541838 wrote: for (int i = 0; i < 1; i++)
You need to learn how to use for loops. You loop will only iterate once...
|
|
|
|
|
Hi.
Do you have an example of what in the code:
"for (int i = 0; i < 1; i++)" I need to change and to what, to make it continue pinging the rest of the host from the host table?
\Jan.
|
|
|
|
|
HI,
I want draw a 3d chart in excell sheet using c# web based appliction .
Please give me an idea about this As soon as possible.
|
|
|
|
|
Murugan k wrote: I want draw a 3d chart in excell sheet using c# web based appliction
Then put it on asp.net forum
|
|
|
|
|
my system attacth to network. when i access to another pc that time open a new window to ask me user name and password. it is another problem. my probleam is i want to create a exe in C#.net. when this will execute the exe to connect another pc enter autometically enter the user name and password. how connect to another pc and put user name and password. i have been use below namespace.
system.net.sockets
system.net
|
|
|
|
|
Hi Rinki,
Are you trying to access the system or access any folder ?
if you dont have the access permission you have to provide the "Network Credentials [ Username, Password , Domain ]" , that why it was asking for username password .
Now what is your objective, just connect with pc or accesing some file?
|
|
|
|
|
no i m try to saying that i want to create exe in C#.net so that when execute the exe to connect network according to IP address and autometically enter the user name and password. last in how i connect network pc using by program. i had been use below namespace.
using.System.Net.Sockets
using.System.Net
|
|
|
|
|
hiiiiiiiiiiiiii
can any body help meeeeeeee
i want microsoft word document 2003 header files,
i want dll. function which it calling the header files using c# 2003 programming language
plz. help me
|
|
|
|
|
Hard to understand your post, but I THINK you want to use the Microsoft tools for office to create Word documents in C# ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hiiiiiiii
thanx mr.Graus
no iwant microsoft tools to calling word automation header files
plz. help me
realy am sad
|
|
|
|
|
What Word Automation header files? Do you mean you want to get access to Word document header information?
Please stop using Textspeak - it's really, really annoying.
|
|
|
|
|
yes
ur write
thats what i want it
thanx i wait ur an swer
|
|
|
|
|
The Microsoft binary file format varies depending on the version.
Microsoft have released the specifications here[^].
If you google there's a lot of information out there. There are also Open Source programs that can save and load .doc/.docx files (Open Office etc...), you could always examine their source code (probably in C).
Dave
|
|
|
|
|
Pete O'Hanlon wrote: Please stop using Textspeak - it's really, really annoying.
I ditto that, and it's beginning to make me really cranky
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Miss_hacker wrote: realy am sad
Dont be that much of Sad
|
|
|
|
|
Miss_hacker wrote: i want microsoft word document 2003 header files,
what does it mean ?
may be you want something like that
Word Automation[^]
|
|
|
|
|
i want to access to word document header information
|
|
|
|
|
Have you looked into the Office Interop Library?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Miss_hacker wrote:
can any body help meeeeeeee
Miss_hacker wrote: plz. help me
Not the way to ask for help around here
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
How to code text formatting in c#.Net
for example you have send mail.you have write a body text box how to code & desgin a bold,italic,color.........(textformatting)
|
|
|
|
|
Set the MailFormat to Html, and use whatever HTML tags you wish.
|
|
|
|
|
one button,one FileUpload,One image box using in one webform(C#.Net).when click the button the image will loaded in imagebox.
please help me
|
|
|
|