An output sending data to target database configured under Splunk DB connect app, fails to send data using a saved search from Splunk. Separating dataset into batches shows that the problem happens with only few records. Output is able to send few records but not all of them. However, removing one column (column containing datatime value) from output mapping, makes things work and output is then able to send data successfully to the DB as all records are inserted in the DB without a problem.
For detailed logs of the problematic output, run the following SPL:
index=_internal sourcetype=dbx_server Log_level=ERROR *<output-name>*
For example, output name is "Proofpoint_TRAP_Output", the SPL looks something like below:
index=_internal sourcetype=dbx_server Log_level=ERROR *Proofppoint_TRAP_Output*
Following errors can be observed:
2024-04-23 07:30:13.786 +0000 [QuartzScheduler_Worker-3] ERROR com.splunk.dbx.service.output.OutputServiceImpl - SQL exception occurred during execute output Proodpoint_TAP_Output
java.sql.BatchUpdateException: Error converting data type nvarchar to datetime2.
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:2116)
at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:128)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java)
at com.splunk.dbx.service.output.OutputServiceImpl.executeBatch(OutputServiceImpl.java:250)
at com.splunk.dbx.service.output.OutputServiceImpl.processInsertion(OutputServiceImpl.java:232)
at com.splunk.dbx.service.output.OutputServiceImpl.output(OutputServiceImpl.java:77)
at com.splunk.dbx.server.dboutput.recordwriter.DbOutputRecordWriter.writeRecords(DbOutputRecordWriter.java:47)
at org.easybatch.core.job.BatchJob.writeBatch(BatchJob.java:234)
at org.easybatch.core.job.BatchJob.call(BatchJob.java:102)
at org.easybatch.extensions.quartz.Job.execute(Job.java:59)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
This error explains that the data type conversion failed for one or more columns. Either the culprit column has invalid values or the values Splunk is sending, are not considered as valid on Database side.
Approach to narrow down the problem further:
Divide the dataset into batches and try inserting using the same output. This will help identify the values of the column that are causing the failure. In this scenario, it was identified that the problem occurs when datetime column named "myTime" has values of dates greater than 12. for example, Records with myTime values being 5/5/2024 are inserted in the DB successfully however records with myTime value being 13/5/2024 (or anything greater) fails using the same output.
This shows that the DB is expecting MM/DD/YYYY format wheres Splunk is sending DD/MM/YYYY format for column myTime. Any value 13/5/2024 (or greater) will be invalid on DB side as there are only 12 months. Changing the format from Splunk side can help resolve this problem.
In order to resolve this issue, the date format needs to be changed. The myTime values from Splunk needs to be reformatted to have dates in format as MM/DD/YYYY instead of DD/MM/YYYY. In this scenario, user was using the following saved search:
index=<index-name> sourcetype=<sourcetype-name>
| table mytime,disposition,Email,subject,RecipientName,RecipientDesignation,RecipientLOS,Territory,RecipientBU
| fillnull value="NA"
Using rex function, the values were formatted in the expected datetime format on DB side. The modified saved search looks something like below:
index=<index-name> sourcetype=<sourcetype-name>
| rex field=mytime "(?<month>\d{2})-(?<day>\d{2})-(?<year>\d{4}) (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})"
| eval mytime = day . "-" . month . "-" . year . " " . hour . ":" . minute . ":" . second
| table mytime,disposition, Email,subject,RecipientName,RecipientDesignation,RecipientLOS,Territory,RecipientBU,messageId,test
| fillnull value="NA"
What rex function is simply doing here is that it is assigning a field name in the DATE value for myTime column and the same column myTime is reformatted using eval function in the expected format.
| Revision | Publish Date | Comments |
|---|---|---|
1.0 |
29-Sep-2026
|
Initial Release |