# Jdbc MSSql Server Connection

**URL:** <https://discuss.elastic.co/t/jdbc-mssql-server-connection/44324>\
**Category:** Logstash\
**Created:** [March 14, 2016, 12:27pm UTC](https://discuss.elastic.co/t/jdbc-mssql-server-connection/44324 "2016-03-14T12:27:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navarro](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Navarro](https://discuss.elastic.co/u/Navarro)\
**Post date:** [March 14, 2016, 12:27pm UTC](https://discuss.elastic.co/t/jdbc-mssql-server-connection/44324/1 "2016-03-14T12:27:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mick66](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@mick66](https://discuss.elastic.co/u/mick66)\
**Post date:** [March 14, 2016, 3:58pm UTC](https://discuss.elastic.co/t/jdbc-mssql-server-connection/44324/2 "2016-03-14T15:58:16Z")

</div>

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.

---

<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:** [July 6, 2017, 5:06am UTC](https://discuss.elastic.co/t/jdbc-mssql-server-connection/44324/3 "2017-07-06T05:06:58Z")

</div>


