# Query to Link Server not working, getting a weird error

**URL:** <https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080>\
**Category:** Logstash\
**Created:** [May 9, 2018, 12:39am UTC](https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080 "2018-05-09T00:39:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kseth](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kseth](https://discuss.elastic.co/u/kseth)\
**Post date:** [May 9, 2018, 12:39am UTC](https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080/1 "2018-05-09T00:39:57Z")

</div>

Hi, I am running a query that uses link server to get data from MS SQL db (joining with postgres in link server). The query runs fine when I run in MS SQL Server but doesn't work in logstash. I am getting this error:

> [2018-05-08T16:35:37,359][ERROR][logstash.pipeline] A plugin had an unrecoverable error. Will restart this plugin.  
> Pipeline\_id:main  
> Plugin: \<LogStash::Inputs::Jdbc jdbc\_driver\_library=\>"sqljdbc4.jar", jdbc\_driver\_class=\>"com.microsoft.sqlserver.jdbc.SQLServerDriver", jdbc\_connection\_string=\>, jdbc\_user=\>, jdbc\_password=\>, statement\_filepath=\>"query.sql", type=\>"wwwproductsfeed", use\_column\_value=\>true, tracking\_column=\>"start\_date", tracking\_column\_type=\>"timestamp", last\_run\_metadata\_path=\>"wwwproductsfeed\_last\_run", lowercase\_column\_names=\>true, parameters=\>{"sql\_last\_value"=\>1969-12-31 16:00:00 -0800}, record\_last\_run=\>true, clean\_run=\>true, id=\>"acfd07b234827ccf7693feafba3289481c53c324e0f22e8fdcd1ae47461cd763", enable\_metric=\>true, codec=\>\<LogStash::Codecs::Plain id=\>"plain\_442777d7-5234-4c6e-8061-c7ebfc306a7f", enable\_metric=\>true, charset=\>"UTF-8"\>, 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\_wait\_time=\>0.5\>  
> Error: can't dup NilClass  
> Exception: TypeError  
> Stack: org/jruby/RubyKernel.java:1882:in `dup' uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/date/format.rb:838:in `\_parse'  
> uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/date.rb:1830:in `parse' /usr/local/Cellar/logstash/6.2.4/libexec/vendor/bundle/jruby/2.3.0/gems/logstash-input-jdbc-4.3.9/lib/logstash/plugin_mixins/value_tracking.rb:87:in `set\_value'  
> /usr/local/Cellar/logstash/6.2.4/libexec/vendor/bundle/jruby/2.3.0/gems/logstash-input-jdbc-4.3.9/lib/logstash/plugin\_mixins/jdbc.rb:237:in `execute_statement' /usr/local/Cellar/logstash/6.2.4/libexec/vendor/bundle/jruby/2.3.0/gems/logstash-input-jdbc-4.3.9/lib/logstash/inputs/jdbc.rb:264:in `execute\_query'  
> /usr/local/Cellar/logstash/6.2.4/libexec/vendor/bundle/jruby/2.3.0/gems/logstash-input-jdbc-4.3.9/lib/logstash/inputs/jdbc.rb:250:in `run' /usr/local/Cellar/logstash/6.2.4/libexec/logstash-core/lib/logstash/pipeline.rb:514:in `inputworker'  
> /usr/local/Cellar/logstash/6.2.4/libexec/logstash-core/lib/logstash/pipeline.rb:507:in `block in start\_input'

The config that I used:

> input {  
> jdbc {  
> jdbc\_driver\_library =\> "sqljdbc4.jar"  
> jdbc\_driver\_class =\> "com.microsoft.sqlserver.jdbc.SQLServerDriver"  
> jdbc\_connection\_string =\>   
> jdbc\_user =\>   
> jdbc\_password =\>   
> statement\_filepath =\> "query.sql"  
> type =\> "wwwproductsfeed"  
> use\_column\_value =\> true  
> tracking\_column =\> start\_date  
> tracking\_column\_type =\> timestamp  
> last\_run\_metadata\_path =\> "wwwproductsfeed\_last\_run"  
> # ------- following are default values --------  
> lowercase\_column\_names =\> true  
> parameters =\> { }  
> record\_last\_run =\> true  
> clean\_run =\> true  
> }  
> }  
> filter {}  
> output {  
> if [type] == "wwwproductsfeed" {  
> csv {  
> csv\_options =\> {"col\_sep" =\> "|" }  
> fields =\> ["product\_id", "name", "price", "recommendable", "link\_url", "rating", "num\_reviews", "brand", "sale\_price", "start\_date"]  
> path =\> "/tmp/product\_%{+YYYY\_MM\_dd}.txt"  
> }  
> }  
> }

- At the query level, I am converting the datetime to date format, which works fine in SQL Server but doesn't work when running the same query via logstash?
- How can I add header in the generated CSV file using the output plugin for csv?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [May 9, 2018, 12:44am UTC](https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080/2 "2018-05-09T00:44:08Z")

</div>

I cannot address your issue, but it looks like you removed the jdbc\_connection\_string in the config, but not the log, and obfuscated the password in the log, but not the config. If that is correct you might want to edit your post.

---

<div class="post-metadata">

**Author:** ![kseth](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kseth](https://discuss.elastic.co/u/kseth)\
**Post date:** [May 9, 2018, 1:20am UTC](https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080/3 "2018-05-09T01:20:49Z")

</div>

@Badger Thanks for your reply. I have intentionally removed connection-string, username and password from my post.

---

<div class="post-metadata">

**Author:** ![kseth](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kseth](https://discuss.elastic.co/u/kseth)\
**Post date:** [May 21, 2018, 5:50pm UTC](https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080/4 "2018-05-21T17:50:23Z")

</div>

BUMP

Any idea why am i seeing this error?

---

<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:** [June 18, 2018, 5:50pm UTC](https://discuss.elastic.co/t/query-to-link-server-not-working-getting-a-weird-error/131080/5 "2018-06-18T17:50:24Z")

</div>

Closed on June 18, 2018, 5:50pm UTC

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