Jdbc MSSql Server Connection

Im trying to establish a connection to a MSsql Server.

This is my config file:

input {

jdbc {
jdbc_driver_library => "/etc/logstash/driver/sqljdbc_4.0/enu/sqljdbc4.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://MYSERVER:MYPORT;databasename=MYDATABASENAME;user=MYUSER,password=MYPASSWORD"
jdbc_user => "MYUSER"
jdbc_password => "MYPASSWORD"

}

}

Everytime i launch logstatsh i get :

Java::ComMicrosoftSqlserverJdbc::SQLServerException ....... Connection Refused.

Can anyone help me? There is no problem with the Firewall

I have an MSSQL jdbc connection working using the following syntax:

input {
  jdbc {
     jdbc_driver_library => "/etc/logstash/driver/sqljdbc_4.0/enu/sqljdbc4.jar"
     jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
     jdbc_connection_string => "jdbc:sqlserver://MYSERVER:MYPORT;databasename=MYDATABASENAME"
     jdbc_user => "MYUSER"
     jdbc_password => "MYPASSWORD"
     statement => "SELECT @@Version"
  }
}

If this does not work then I would check the SQL Server for the following:

  • Is the port correct in the jdbc connection? MSSQL can use dynamic ports, so you need to confirm this is correct for the target instance.

  • Check the SQL Log for failed login attempts from the login.

  • Check the SQL Login has has access to the database.

2 Likes