Question: I'm trying to download a file by clicking on an a href link with an onClick event:

```
<a href="#download" onClick="downloadFile('@(elem.Attachment)')">@(elem.Attachment.Split('/').Last())</a>

```

in elem.Attachment, there is the full path of the file i'm trying to download.

My C# method to download the file in the Controller is the following:

```
public FileResult DownloadFile(string path)
    {
        return File(path, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(path));
    }

```

The last method im using is the javascript function "downloadFile":

```
function downloadFile(path){
        Ext.Ajax.request({
            url: '/Home/DownloadFile',
            type: "post",
            params: { path: path },
            success: function (response, opts) {

            },
            failure: function (response, opts) {
                alert('server-side failure with status code ' + response.status);
            }
        });
    }

```

I debugged the program, and it calls the method "DownloadFile" of my controller, passing the right path.

How can i download now the returned FileResult from the Controller using the Ajax request?

Answer: 
Try doing something like this in hibernate configuration:

```
<property name="connection.autoReconnect"> true </ property>
<property name="connection.autoReconnectForPools"> true </ property>
<property name="connection.is-connection-validation-required"> true </ property>

```
Try adding `testOnBorrow="true" and validationQuery="SELECT 1" validationInterval="60000"`
This happens when DB server terminates connections. After adding these parameters, the connection pool will validate the connection before giving it to the application. If it is not valid, the connection will be discarded and a new one will be created.