0

I want to specify the timeout execution myself in the select query.

 e.g.; select timeout(5) * from tableName    (time exceeded, because records will not arrive before 50 seconds)

   or

 e.g.; 
      set timeout(5)
      select * from tableName    (time exceeded, because records will not arrive before 50 seconds)
Serturk
  • 1
  • 1

1 Answers1

0

it is possible in the code

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout(v=vs.110).aspx

  using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnStringName"].ToString()))
  using (SqlCommand mySqlCommand = new SqlCommand())
    {
        try
        {
            conn.Open();
            mySqlCommand.Connection = conn;
            mySqlCommand.CommandType = CommandType.StoredProcedure;
            mySqlCommand.CommandText = "getCities";
            mySqlCommand.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ConnectionTimeout"].ToString());

            mySqlCommand.Parameters.Add("@param", SqlDbType.VarChar).Value = param;     
            da.SelectCommand = mySqlCommand;
            da.Fill(ds, "cities");
        }
        catch (Exception ex)
        {                
        }
    } // end using  


------------ you can try
OPENQUERY (Transact-SQL) http://technet.microsoft.com/en-us/library/ms188427.aspx

check this:
connections OPENDATASOURCE http://technet.microsoft.com/en-us/library/ms179856.aspx

Connect timeout DBPROP_INIT_TIMEOUT Time-out value after which the connection try fails.

Valentin Petkov
  • 1,570
  • 18
  • 23