check internet connection + internet speed

how to check if PC is connected to internet using C# 2005 and on what speed it's connected




Answer this question

check internet connection + internet speed

  • Roman Golovin MSFT

    I will send you later the code
  • jessie2

    To check the internet access:

    Response.Redirect (“http://....”);

    About the speed connection I will try to find somewhat out. Maybe later.

    Have a fun!

    Valentin

    MCP C#

    Do not hesitate to contact me!

    www.wwv-it.eu

    valentin.welter@t-online.de


  • PrasNuts

    i am talking about checking it by code not throught IDE!!



  • JBClifton

    hi you can do that..for cheaking internet connection:

    [DllImport("wininet.dll")]

    private static extern bool InternetGetConnectedState(ref uint connected, uint reserved);

    static uint uConnection = 0x20;

    /// <summary>

    /// Returns true if it have detected an active Internet connection.

    /// </summary>

    public static bool HasInternetConnection

    {

    get { return InternetGetConnectedState(ref uConnection, 0); }

    }



  • y0ngb00n

    this is windows application not web



  • David Friesen, B.Eng

    You can start a web application also locally from PC. It is not necessary to upload (deploy) the web application on host servers.

    For a windows application you need internet access only for database connections on host servers.

  • wxDiilbert

    Add a new database connection

    Navigation

    Menu bar a View a Server Explorer aData Conections a Right mouse keyaAdd Connection

    Test a database connection

    Navigation

    Menu bar a View a Server Explorer aselect a database a Right mouse keyaModify Connection

    Have a fun!

    Valentin

    MCP C#

    Do not hesitate to contact me!

    www.wwv-it.eu


  • Hanu Kommalapati

    using System;

    using System.Drawing;

    using System.Collections;

    using System.ComponentModel;

    using System.Windows.Forms;

    using System.Data;

    namespace WinTestDatabaseConnection

    {

    /// <summary>

    /// Zusammenfassung fur Form1.

    /// </summary>

    public class Form1 : System.Windows.Forms.Form

    {

    private System.Windows.Forms.Button TestConnection;

    private System.Windows.Forms.TextBox textBox1;

    private System.Windows.Forms.TextBox textBox2;

    private System.Data.SqlClient.SqlConnection sqlConnection1;

    private System.Windows.Forms.Label label1;

    /// <summary>

    /// Erforderliche Designervariable.

    /// </summary>

    private System.ComponentModel.Container components = null;

    public Form1()

    {

    //

    // Erforderlich fur die Windows Form-Designerunterstutzung

    //

    InitializeComponent();

    //

    // TODO: Fugen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu

    //

    }

    /// <summary>

    /// Die verwendeten Ressourcen bereinigen.

    /// </summary>

    protected override void Dispose( bool disposing )

    {

    if( disposing )

    {

    if (components != null)

    {

    components.Dispose();

    }

    }

    base.Dispose( disposing );

    }

    #region Vom Windows Form-Designer generierter Code

    /// <summary>

    /// Erforderliche Methode fur die Designerunterstutzung.

    /// Der Inhalt der Methode darf nicht mit dem Code-Editor geandert werden.

    /// </summary>

    private void InitializeComponent()

    {

    this.TestConnection = new System.Windows.Forms.Button();

    this.textBox1 = new System.Windows.Forms.TextBox();

    this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();

    this.textBox2 = new System.Windows.Forms.TextBox();

    this.label1 = new System.Windows.Forms.Label();

    this.SuspendLayout();

    //

    // TestConnection

    //

    this.TestConnection.Location = new System.Drawing.Point(256, 152);

    this.TestConnection.Name = "TestConnection";

    this.TestConnection.Size = new System.Drawing.Size(120, 23);

    this.TestConnection.TabIndex = 0;

    this.TestConnection.Text = "Test Connection";

    this.TestConnection.Click += new System.EventHandler(this.TestConnection_Click);

    //

    // sqlConnection1

    //

    this.sqlConnection1.ConnectionString = "workstation id=\"...\";packet size=4096;user id=...;password=...;da" +

    "ta source=\"...\";persist security info=False;initial catalog=" +

    "...";

    //

    // textBox1

    //

    this.textBox1.Location = new System.Drawing.Point(24, 48);

    this.textBox1.Multiline = true;

    this.textBox1.Name = "textBox1";

    this.textBox1.Size = new System.Drawing.Size(696, 48);

    this.textBox1.TabIndex = 1;

    this.textBox1.Text = this.sqlConnection1.ConnectionString;

    //

    // textBox2

    //

    this.textBox2.Location = new System.Drawing.Point(224, 200);

    this.textBox2.Name = "textBox2";

    this.textBox2.ReadOnly = true;

    this.textBox2.Size = new System.Drawing.Size(200, 20);

    this.textBox2.TabIndex = 2;

    this.textBox2.Text = "";

    //

    // label1

    //

    this.label1.Location = new System.Drawing.Point(32, 16);

    this.label1.Name = "label1";

    this.label1.Size = new System.Drawing.Size(296, 23);

    this.label1.TabIndex = 3;

    this.label1.Text = "Enter connection string. Default : initial connection string";

    //

    // Form1

    //

    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

    this.ClientSize = new System.Drawing.Size(744, 302);

    this.Controls.Add(this.label1);

    this.Controls.Add(this.textBox2);

    this.Controls.Add(this.textBox1);

    this.Controls.Add(this.TestConnection);

    this.Name = "Form1";

    this.Text = "Form1";

    this.ResumeLayout(false);

    }

    #endregion

    /// <summary>

    /// Der Haupteinstiegspunkt fur die Anwendung.

    /// </summary>

    [STAThread]

    static void Main()

    {

    Application.Run(new Form1());

    }

    private void TestConnection_Click(object sender, System.EventArgs e)

    {

    try

    {

    if (textBox1.Text.Length != 0)

    this.sqlConnection1.ConnectionString = textBox1.Text;

    else

    textBox1.Text = this.sqlConnection1.ConnectionString;

    }

    catch

    {

    textBox2.Text = "Invalid connection string";

    return;

    }

    try

    {

    sqlConnection1.Open();

    textBox2.Text = "Connection established";

    }

    catch (System.Exception ex)

    {

    textBox2.Text = "Connection failed";

    }

    finally

    {

    sqlConnection1.Close ();

    }

    }

    }

    }


  • jbranton

    and that's what i have

    a windows application accessin a database on remote server via internet and i need to check before connecting that internet connection is available.



  • check internet connection + internet speed