I want to test the database can be connected in fast seconds,for example i want to test it in 3 seconds. I wrote these codes.
 bool IsCanConnectioned = false;
            string connStr = connectionString + ";Connection Timeout=3000";
            SqlConnection sqlConnection = new SqlConnection(connStr);
            try
            {
                sqlConnection.Open();
                IsCanConnectioned = true;
            }
            catch
            {
                IsCanConnectioned = false;
            }
            finally
            {
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
              return IsCanConnectioned;
I broken my network to database for this test, but it's no working to set the connection timeout 3000 or 3. It will throw exception after a long time about more than 15 seconds. (I guess it's because the network timeout) I want to test it in 3 seconds. so is there a good way to do this.
may be It could start a new thread to connect the database,and I wait for the thread 3 seconds,when it's no response or return false,I said the database couldn't be connected,but is there a better way?