All Apps and Add-ons

Splunk DB Connect 2: I get results in connection --> query, but why do I not get results using dbquery in a Splunk search?

casieowen
Engager

Hi,

I need to be able to:
1) use splunk's visualization capabilities (like those available after querying event data -- using the visualization tab) based on SQL data.
2) correlate data in SQL tables with event data in splunk.

I have a valid SQL connection. If I go to the connection, see that it's valid/green, click the query tab, and run a query, I get results. Like this (query.png)
alt text

But if I go to splunk --> search (not within the DB connect app) and try this query, I get no results. As far as I can tell from what I've read online, the syntax is correct. See this (search.png):
alt text

I guess it makes sense that I wouldn't get results here since data in the SQL tables isn't event data. But yet, how do I correlate indexed event data with the data in SQL tables? Is a saved DB Input or DB Lookup required?

Also, is there any good, step by step documentation anywhere? I've found some things online, like general concepts for db lookup and db input, and some syntax for db query, but nothing step-by step.

Thanks in advance.

0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

Did you mean to

| dbquery "test" "select * from testdata"

(note the pipe at the beginning)?
Without a pipe, you are doing a search for the literal strings "dbquery", "test" and "select *..." in your default searched indexes, because if you do not begin a splunk search in that search box with a pipe, splunk assumes a search command first, and everything you entered becomes a literal search (or key-value-pairs, e.g. index=_internal).

View solution in original post

0 Karma

jeffland
SplunkTrust
SplunkTrust

Did you mean to

| dbquery "test" "select * from testdata"

(note the pipe at the beginning)?
Without a pipe, you are doing a search for the literal strings "dbquery", "test" and "select *..." in your default searched indexes, because if you do not begin a splunk search in that search box with a pipe, splunk assumes a search command first, and everything you entered becomes a literal search (or key-value-pairs, e.g. index=_internal).

0 Karma

casieowen
Engager

Thanks! That + this thread got me there: https://answers.splunk.com/answers/227030/splunk-db-connect-2-what-is-the-proper-syntax-for.html.

In my case, the syntax that worked within search is:

| dbxquery query="SELECT%20*%20FROM%20TestData"connection="casieolocalsql"
0 Karma

ppablo
Retired

Hi @casieowen

Glad you found an answer to your question 🙂 Please don't forget to resolve this post by clicking "Accept" directly below @jeffland's answer and upvote the comment that helped you find your solution. Thanks!

Patrick

0 Karma

casieowen
Engager

Thanks for the response.

When I try

| dbquery "test" "select * from testdata

I get:

Unknown search command 'dbquery'.

I see one thread (https://answers.splunk.com/answers/75874/unknown-search-command-dbquery-for-non-admin-users.html) where this error was a result of a perms issue. I'm running this query as the built in splunk admin and the identity in the SQL connection is a db_owner of the database I'm querying. (Seems, if it was a perms issue at all, it wouldn't be perms to SQL since the query works in connection-->query).

Are there non-perms related causes for the Unknown search command 'dbquery'. error?

Thanks in advance.

0 Karma

jeffland
SplunkTrust
SplunkTrust

Oh! I just noticed that DB Connect App 2 changed to dbxquery. See if that does it.

Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...