# Logstash cannot connect to Azure MS Sql database

**URL:** <https://discuss.elastic.co/t/logstash-cannot-connect-to-azure-ms-sql-database/167831>\
**Category:** Logstash\
**Created:** [February 11, 2019, 11:27am UTC](https://discuss.elastic.co/t/logstash-cannot-connect-to-azure-ms-sql-database/167831 "2019-02-11T11:27:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [February 11, 2019, 11:27am UTC](https://discuss.elastic.co/t/logstash-cannot-connect-to-azure-ms-sql-database/167831/1 "2019-02-11T11:27:42Z")

</div>

I am trying to extract info from all databases using Logstash and inserting them into Elasticsearch. While it works for all databases with specified localhost addresses, I am having trouble connecting to databases in AZURE cloud.  
The JDBC input of my logstash.conf file looks as follows -

```
jdbc { 
    jdbc_connection_string => "jdbc:sqlserver://hostname.database.windows.net:1433;database= ****** ;encrypt=true;hostNameInCertificate=*.database.windows.net"
    jdbc_user => "<Username>"
jdbc_password => "<Password>"
    jdbc_driver_library => "/config-dir/<Latest JAR File>"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    statement => "<SQL QUERY>"
schedule => "* * * * *"
type => "type_1"
}

```

The error I am getting after running the docker-compose file is -  
logstash | [2019-02-11T05:53:40,429][ERROR][logstash.inputs.jdbc] Unable to connect to database. Tried 1 times {:error\_message=\>"Java::ComMicrosoftSqlserverJdbc::SQLServerException: Cannot open server "logstash" requested by the login. The login failed."}  
logstash | [2019-02-11T05:53:40,431][ERROR][logstash.pipeline] A plugin had an unrecoverable error. Will restart this plugin.  
logstash | Pipeline\_id:main  
logstash |   
logstash | Error: Java::ComMicrosoftSqlserverJdbc::SQLServerException: Cannot open server "logstash" requested by the login. The login failed.  
logstash | Exception: Sequel::DatabaseConnectionError

The credentials are fine, I have connected the Azure database from my local MSSQL instance. But somehow Logstash cannot do so. Can anyone help me identify what am I missing here? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [February 11, 2019, 4:12pm UTC](https://discuss.elastic.co/t/logstash-cannot-connect-to-azure-ms-sql-database/167831/2 "2019-02-11T16:12:44Z")

</div>

I have solved the problem. While entering the "Username" field for AZURE databases, we should modify it like "Username@hostname" where "hostname" defines the SQL Azure Server ID as in the connection string.

---

<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:** [March 11, 2019, 4:19pm UTC](https://discuss.elastic.co/t/logstash-cannot-connect-to-azure-ms-sql-database/167831/3 "2019-03-11T16:19:48Z")

</div>

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