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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...