0

i am trying to make a c# console application my basic objective its to be cheking a "status" field in mysql database it is on a server... i tried it but after 20 min approximatly it gives me a timeout error... is there a way i can do this permanently?? thanks in advanced... this is something i have so you have an idea.

namespace blabla
 {
    class Program
    {
      static void Main(string[] args)
       {   

        int flag = 0;

        while (flag < 1)
        {
            string connstr = "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword";

            MySqlConnection conn = new MySqlConnection(connstr);
            MySqlCommand command = conn.CreateCommand();
            command.CommandText = "select * from table where status = 1  ";
            conn.Open();
            try
            {

            }
            catch (Exception ex)
            {
               Console.Write(ex.Message);
            }

            MySqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                // do things

            }

            conn.Close();

        }

    }
}
Aroque
  • 1
  • 2
  • When you say "after 20 min approximatly it gives me a timeout error" do you mean your program runs for 20 minutes, doing things, and then gives you an error, or do you mean it does nothing for 20 minutes, then gives the error? Do you mean a .NET exception? If so, please show the exception message in your question. – Dour High Arch May 09 '13 at 20:42
  • Your code is very strange; it contains a `try` clause and `while` loop that do nothing. Have you omitted code? Why do you think the code you omitted is not the cause of the problem? You loop `while (flag < 1)` but never increment `flag`, so your code will go into an infinite loop; is that what you mean by "timeout error"? – Dour High Arch May 09 '13 at 20:43

1 Answers1

0

What does the line string connstr = "blablabla"; achieve?

This is where you need to specify the connection string, else the program has no means of contacting the database.

Try this with your credentials:

connstr = "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword";

Beyond that, your try catch block wont catch any errors:

try
{
    conn.Open();
    MySqlDataReader reader = command.ExecuteReader();
    while (reader.Read())
    {
    // do things
    }
    conn.Close();
}

catch (Exception ex)
{
   Console.Write(ex.Message);
}
devilfish17
  • 337
  • 3
  • 10