diff --git a/web/pgadmin/static/js/sqleditor/filter_dialog.js b/web/pgadmin/static/js/sqleditor/filter_dialog.js
index 8a48c867..fa9eb6bb 100644
--- a/web/pgadmin/static/js/sqleditor/filter_dialog.js
+++ b/web/pgadmin/static/js/sqleditor/filter_dialog.js
@@ -7,17 +7,32 @@ import Backform from 'pgadmin.backform';
 import axios from 'axios';
 import queryToolActions from 'sources/sqleditor/query_tool_actions';
 import filterDialogModel from 'sources/sqleditor/filter_dialog_model';
+import {handleQueryToolAjaxError} from 'sources/sqleditor/query_tool_http_error_handler';
 
 let FilterDialog = {
-  'dialog': function(handler) {
+  geturl: function(transId, reconnect) {
+    let url = url_for('sqleditor.get_filter_data', {
+      'trans_id': transId,
+    });
+
+    if(reconnect) {
+      url += '?connect=1';
+    }
+
+    return url;
+  },
+
+  'dialog': function(handler, reconnect) {
     let title = gettext('Sort/Filter options');
-    axios.get(
-      url_for('sqleditor.get_filter_data', {
-        'trans_id': handler.transId,
-      }),
-      { headers: {'Cache-Control' : 'no-cache'} }
-    ).then(function (res) {
-      let response = res.data.data.result;
+
+    $.ajax({
+      url: this.geturl(handler.transId, reconnect),
+      headers: {
+        'Cache-Control' : 'no-cache',
+      },
+    })
+    .done(function (res) {
+      let response = res.data.result;
 
       // Check the alertify dialog already loaded then delete it to clear
       // the cache
@@ -234,6 +249,9 @@ let FilterDialog = {
       });
 
       Alertify.filterDialog(title).resizeTo('65%', '60%');
+    })
+    .fail(function(e) {
+      handleQueryToolAjaxError(pgAdmin, handler, e, '_show_filter', [], true);
     });
   },
 };
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index 9d8a256c..3f0055de 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -1526,7 +1526,11 @@ def get_filter_data(trans_id):
     Args:
         trans_id: unique transaction id
     """
-    return FilterDialog.get(*check_transaction_status(trans_id))
+
+    status, error_msg, conn, trans_obj, session_ob = \
+        check_transaction_status(trans_id)
+
+    return FilterDialog.get(status, error_msg, conn, trans_obj, session_ob)
 
 
 @blueprint.route(
@@ -1541,8 +1545,12 @@ def set_filter_data(trans_id):
     Args:
         trans_id: unique transaction id
     """
+
+    status, error_msg, conn, trans_obj, session_ob = \
+        check_transaction_status(trans_id)
+
     return FilterDialog.save(
-        *check_transaction_status(trans_id),
+        status, error_msg, conn, trans_obj, session_ob,
         request=request,
         trans_id=trans_id
     )
diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py
index fbe37df6..5a2918d7 100644
--- a/web/pgadmin/tools/sqleditor/command.py
+++ b/web/pgadmin/tools/sqleditor/command.py
@@ -552,45 +552,40 @@ class TableCommand(GridCommand):
         all_sorted_columns = []
         data_sorting = self.get_data_sorting()
         all_columns = []
-        if conn.connected():
+        # Fetch the primary key column names
+        query = render_template(
+            "/".join([self.sql_path, 'primary_keys.sql']),
+            obj_id=self.obj_id
+        )
 
-            # Fetch the primary key column names
-            query = render_template(
-                "/".join([self.sql_path, 'primary_keys.sql']),
-                obj_id=self.obj_id
+        status, result = conn.execute_dict(query)
+
+        if not status:
+            raise Exception(result)
+
+        for row in result['rows']:
+            all_columns.append(row['attname'])
+            all_sorted_columns.append(
+                {
+                    'name': row['attname'],
+                    'order': self.get_pk_order()
+                }
             )
 
-            status, result = conn.execute_dict(query)
-            if not status:
-                raise Exception(result)
+        # Fetch the rest of the column names
+        query = render_template(
+            "/".join([self.sql_path, 'get_columns.sql']),
+            obj_id=self.obj_id
+        )
+        status, result = conn.execute_dict(query)
+        if not status:
+            raise Exception(result)
 
-            for row in result['rows']:
+        for row in result['rows']:
+            # Only append if not already present in the list
+            if row['attname'] not in all_columns:
                 all_columns.append(row['attname'])
-                all_sorted_columns.append(
-                    {
-                        'name': row['attname'],
-                        'order': self.get_pk_order()
-                    }
-                )
-
-            # Fetch the rest of the column names
-            query = render_template(
-                "/".join([self.sql_path, 'get_columns.sql']),
-                obj_id=self.obj_id
-            )
-            status, result = conn.execute_dict(query)
-            if not status:
-                raise Exception(result)
 
-            for row in result['rows']:
-                # Only append if not already present in the list
-                if row['attname'] not in all_columns:
-                    all_columns.append(row['attname'])
-        else:
-            raise Exception(
-                gettext('Not connected to server or connection with the '
-                        'server has been closed.')
-            )
         # If user has custom data sorting then pass as it as it is
         if data_sorting and len(data_sorting) > 0:
             all_sorted_columns = data_sorting
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 1316c7be..cc7509f8 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -3006,8 +3006,17 @@ define('tools.querytool', [
 
       // This function will show the filter in the text area.
       _show_filter: function() {
-        let self = this;
-        FilterHandler.dialog(self);
+        let self = this,
+          reconnect = false;
+
+        /* When server is disconnected and connected, connection is lost,
+         * To reconnect pass true
+         */
+        if (arguments.length > 0 &&
+          arguments[arguments.length - 1] == 'connect') {
+          reconnect = true;
+        }
+        FilterHandler.dialog(self, reconnect);
       },
 
       // This function will include the filter by selection.
diff --git a/web/pgadmin/tools/sqleditor/utils/filter_dialog.py b/web/pgadmin/tools/sqleditor/utils/filter_dialog.py
index d7064979..1bfa2e73 100644
--- a/web/pgadmin/tools/sqleditor/utils/filter_dialog.py
+++ b/web/pgadmin/tools/sqleditor/utils/filter_dialog.py
@@ -11,9 +11,11 @@
 import pickle
 import simplejson as json
 from flask_babelex import gettext
+from flask import current_app
 from pgadmin.utils.ajax import make_json_response, internal_server_error
 from pgadmin.tools.sqleditor.utils.update_session_grid_transaction import \
     update_session_grid_transaction
+from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost
 
 
 class FilterDialog(object):
@@ -32,7 +34,16 @@ class FilterDialog(object):
         if status and conn is not None and \
                 trans_obj is not None and session_obj is not None:
             msg = gettext('Success')
-            columns, column_list = trans_obj.get_all_columns_with_order(conn)
+
+            try:
+                columns, column_list = \
+                    trans_obj.get_all_columns_with_order(conn)
+            except (ConnectionLost, SSHTunnelConnectionLost):
+                raise
+            except Exception as e:
+                current_app.logger.error(e)
+                raise
+
             sql = trans_obj.get_filter()
         else:
             status = False
