# How can i catch and store an error in output plugin (Unable to connect database)

**URL:** <https://discuss.elastic.co/t/how-can-i-catch-and-store-an-error-in-output-plugin-unable-to-connect-database/147776>\
**Category:** Logstash\
**Created:** [September 7, 2018, 9:25pm UTC](https://discuss.elastic.co/t/how-can-i-catch-and-store-an-error-in-output-plugin-unable-to-connect-database/147776 "2018-09-07T21:25:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jam1142](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@jam1142](https://discuss.elastic.co/u/jam1142)\
**Post date:** [September 7, 2018, 9:25pm UTC](https://discuss.elastic.co/t/how-can-i-catch-and-store-an-error-in-output-plugin-unable-to-connect-database/147776/1 "2018-09-07T21:25:16Z")

</div>

Hi,  
I am using JDBC to get data from SQL server, for handling connectivity issues i disabled SQL server and logstash start throwing below error. Does anybody has any idea how can i put condition on this and store error detail in another index. see below error message

[2018 - 09 - 07T16: 09: 15, 165][ERROR][logstash.inputs.jdbc]Unable to connect to database.Tried 1 times {  
: error\_message =\> "Java::ComMicrosoftSqlserverJdbc::SQLServerException: The TCP/IP connection to the host 10.20.32.136, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."."  
}  
[2018 - 09 - 07T16: 09: 15, 165][ERROR][logstash.pipeline]A plugin had an unrecoverable error.Will restart this plugin.  
Pipeline\_id: main  
Plugin: \< LogStash::Inputs::Jdbc jdbc\_driver\_library =\> "C:\logstash\lib\sqljdbc41.jar", jdbc\_driver\_class =\> "com.microsoft.sqlserver.jdbc.SQLServerDriver", jdbc\_connection\_string =\> "jdbc:sqlserver://10.20.32.136:1433", jdbc\_user =\> "logstash", jdbc\_password =\> \< password \> , type =\> "startup", codec =\> \< LogStash::Codecs::JSON id =\> "json\_d94d23db-ba90-4575-a9db-ce2894aa3b7d", enable\_metric =\> true, charset =\> "UTF-8" \> , statement =\> "SELECT TOP 1 object\_name from master.sys.dm\_os\_performance\_counters", id =\> "29a117901c739d61d7b3c1aa6e22bbb573fa327952dd0615f8ea9cb2b3e8ead4", enable\_metric =\> true, jdbc\_paging\_enabled =\> false, jdbc\_page\_size =\> 100000, jdbc\_validate\_connection =\> false, jdbc\_validation\_timeout =\> 3600, jdbc\_pool\_timeout =\> 5, sql\_log\_level =\> "info", connection\_retry\_attempts =\> 1, connection\_retry\_attempts\_w  
ait\_time =\> 0.5, parameters =\> {  
"sql\_last\_value" =\> 2018 - 09 - 07 15: 55: 00 - 0500  
}, last\_run\_metadata\_path =\> "C:\Users\jqamer/.logstash\_jdbc\_last\_run", use\_column\_value =\> false, tracking\_column\_type =\> "numeric", clean\_run =\> false, record\_last\_run =\> true, lowercase\_column\_names =\> true \>  
Error: Java::ComMicrosoftSqlserverJdbc::SQLServerException: The TCP / IP connection to the host 10.20.32.136, port 1433 has failed.Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".  
Exception: Sequel::DatabaseConnectionError  
Stack: com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(com / microsoft / sqlserver / jdbc / SQLServerException.java: 191)  
com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(com / microsoft / sqlserver / jdbc / SQLServerException.java: 242)  
com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(com / microsoft / sqlserver / jdbc / IOBuffer.java: 2280)  
com.microsoft.sqlserver.jdbc.TDSChannel.open(com / microsoft / sqlserver / jdbc / IOBuffer.java: 493)  
com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(com / microsoft / sqlserver / jdbc / SQLServerConnection.java: 1388)  
com.microsoft.sqlserver.jdbc.SQLServerConnection.login(com / microsoft / sqlserver / jdbc / SQLServerConnection.java: 1069)  
com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(com / microsoft / sqlserver / jdbc / SQLServerConnection.java: 905)  
com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(com / microsoft / sqlserver / jdbc / SQLServerConnection.java: 452)  
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(com / microsoft / sqlserver / jdbc / SQLServerDriver.java: 1014)  
java.lang.reflect.Method.invoke(java / lang / reflect / Method)  
org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org / jruby / javasupport / JavaMethod.java: 468)  
org.jruby.javasupport.JavaMethod.invokeDirect(org / jruby / javasupport / JavaMethod.java: 326)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.adapters.jdbc.connect(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / adapters / jdbc.rb: 215)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.connection\_pool.make\_new(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / connection\_pool.rb: 127)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.connection\_pool.threaded.assign\_connection(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / connection\_pool / threaded.rb: 206)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.connection\_pool.threaded.acquire(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / connection\_pool / threaded.rb: 138)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.connection\_pool.threaded.hold(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / connection\_pool / threaded.rb: 90)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.database.connecting.synchronize(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / database / connecting.rb: 270)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.database.connecting.test\_connection(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / database / connecting.rb: 279)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.database.connecting.connect(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / database / connecting.rb: 58)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.sequel\_minus\_5\_dot\_10\_dot\_0.lib.sequel.core.connect(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / sequel - 5.10.0 / lib / sequel / core.rb: 116)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.logstash\_minus\_input\_minus\_jdbc\_minus\_4\_dot\_3\_dot\_9.lib.logstash.plugin\_mixins.jdbc.block in jdbc\_connect(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / logstash - input - jdbc - 4.3.9 / lib / logstash / plugin\_mixins / jdbc.rb: 114)  
org.jruby.RubyKernel.loop(org / jruby / RubyKernel.java: 1292)  
C\_3a\_.logstash.vendor.bundle.jruby.$2\_dot\_3\_dot\_0.gems.logstash\_minus\_input\_minus\_jdbc\_minus\_4\_dot\_3\_dot\_9.lib.logstash.plugin\_mixins.jdbc.jdbc\_connect(C: /logstash/vendor / bundle / jruby / 2.3.0 / gems / logstash - input - jdbc - 4.3.9 / lib / logstash / plugin\_mixins / jdbc.rb: 111)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 5, 2018, 9:25pm UTC](https://discuss.elastic.co/t/how-can-i-catch-and-store-an-error-in-output-plugin-unable-to-connect-database/147776/2 "2018-10-05T21:25:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
