Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:13:50+00:00 2026-06-04T22:13:50+00:00

I want to make my code to be able to check if internet connection

  • 0

I want to make my code to be able to check if internet connection is established.
After that I will normally save records in the database on the server, but I want to be able to save records in the local database on pc everytime the connection is lost and before every normal connection on the server check if the local database is empty and copy everything from local database to server database.

Here is my code that I use now:

//open database connection
con = new MySqlConnection("server=192...;database=GPS_data;uid=root;pwd=******");
con.Open();

//check if card reader is loged
if (card_number != null)
{
    cmd = new MySqlCommand("insert into data values (null, ?Parname , ?Parname2, ?Parname3, ?Parname4, ?Parname5, ?Parname6, ?Parname7);", con);
    cmd.Parameters.Add("?Parname", MySqlDbType.Double).Value = Math.Round(deciLat, 5);
    cmd.Parameters.Add("?Parname2", MySqlDbType.Double).Value = Math.Round(deciLon, 5);
    cmd.Parameters.Add("?Parname3", MySqlDbType.Timestamp).Value = DateTime.Now;
    cmd.Parameters.Add("?Parname4", MySqlDbType.VarChar).Value = card_number;
    cmd.Parameters.Add("?Parname5", MySqlDbType.VarChar).Value = ConfigSettings.ReadSetting("reg");
    cmd.Parameters.Add("?Parname6", MySqlDbType.VarChar).Value = ConfigSettings.ReadSetting("ser");
    cmd.Parameters.Add("?Parname7", MySqlDbType.Double).Value = ellipHeight;
    cmd.ExecuteNonQuery();
    lastDBUpdate = DateTime.Now;
}
else //in the case when user is not logged in with the card
{
    cmd = new MySqlCommand("insert into data values (null, ?Parname , ?Parname2, ?Parname3, ?Parname4, ?Parname5, ?Parname6, ?Parname7);", con);
    cmd.Parameters.Add("?Parname", MySqlDbType.Double).Value = Math.Round(deciLat, 5);
    cmd.Parameters.Add("?Parname2", MySqlDbType.Double).Value = Math.Round(deciLon, 5);
    cmd.Parameters.Add("?Parname3", MySqlDbType.Timestamp).Value = DateTime.Now;
    cmd.Parameters.Add("?Parname4", MySqlDbType.VarChar).Value = null;
    cmd.Parameters.Add("?Parname5", MySqlDbType.VarChar).Value = ConfigSettings.ReadSetting("reg");
    cmd.Parameters.Add("?Parname6", MySqlDbType.VarChar).Value = ConfigSettings.ReadSetting("reg");
    cmd.Parameters.Add("?Parname7", MySqlDbType.Double).Value = ellipHeight;
    cmd.ExecuteNonQuery();
    lastDBUpdate = DateTime.Now;
}

So this part of the code goes on the server.
I mean there shouldn’t be any special connection check as this would probably result with an error if connection is not established.

I want to add saving to a local database depending on connection, so connection=lost ( save in the local databse), connection=established(first check if local database is empty= if not copy to server database, continue recording on server)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:13:51+00:00Added an answer on June 4, 2026 at 10:13 pm

    Create a function GetConnectionString() and use this function to get connection always.

    Write down the code to check for internet existence and return the connection on basis of that.

    public string GetConnectionString()
        {
            string SqlConString1 = value;//Read from config
            string SqlConString2 = value;//Read from config
            WebClient client = new WebClient();
            try
            {
                using (client.OpenRead("http://www.google.com"))
                {
                }
                return SqlConString1 ;
            }
            catch (WebException)
            {
                return SqlConString2 ;
            }
        }
    

    Refer this for more code to check for internet connectivity 1

    Refer this for more code to check for internet connectivity 2

    Refer this for more code to check for internet connectivity 3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a code snippet database web application. Would the best way
I want to make a code that counts the click on the link which
For some MATLAB code that I want to make executable, I need the location
I have this code that I want to make point-free; (\k t -> chr
I use PhpStorm. I want to make snippets of code and then assign shortcuts
Want to code a key pad for an calculator. What I want to make
I want to make sure the first 4 letters in a eight character code
i want to make a system call in my python code but the problem
I want to make this 1332251639632 to this 1332251639 I try this code, but
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.