This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Error -2147217913 in LabVIEW Database Connectivity Toolkit

Updated Jul 4, 2024

Reported In

Software

  • LabVIEW
  • LabVIEW Database Connectivity Toolkit

Issue Details

I am receiving the following error from the LabVIEW Database Connectivity Toolkit when I try writing to my SQL database:

Error -2147217913 occurred at NI_Database_API.lvlib:Cmd Execute.vi->NI_Database_API.lvlib:DB Tools Insert Data.vi-><VI name>

Possible reason(s):
ADO Error: 0x80040E07
Exception occured in Microsoft OLE DB Provider for SQL Server: Error converting data type varchar to numeric. in NI_Database_API.lvlib:Rec Create - Command.vi->NI_Database_API.lvlib:Cmd Execute.vi->NI_Database_API.lvlib:DB Tools Insert Data.vi-><VI name>


error.JPG

Solution

This error means that there is a data type mismatch between what the LabVIEW Database Connectivity Toolkit is writing and what the database expects to receive. Follow these recommendations to address the issue:
 
  • Use the available data types in the LabVIEW Database Connectivity Toolkit and map them to the appropriate data type in the SQL database. The LabVIEW
    Database Connectivity Toolkit User Manual
     defines the supported data types in Chapter 4.
    • For example, if you try to write a boolean value in LabVIEW (True or False constant) to a SQL column of the type numeric, error -2147217913 will be reported.
  • Make sure you are writing data in the form and order the database is expecting. For example, if you are writing a cluster of 2 elements in LabVIEW, make sure the data type of those two values are compatible with the column data type definition configured in the database. 
In the following image, assuming there are two columns in the table, one having a varchar definition and the other one a numeric definition, the VI will return error -2147217913, as it tries to write a string value ("365FZD") to a SQL numeric column.
 
causeError.JPG
The order of the elements in the column input should be VarcharColumn and then NumericColumn in the example shown, or have the DBL value in the data cluster as the first element and the string value as the second element.
 
  • If you are sure the data is of the correct type, the problem may be occurring if your data goes out of the valid range. For example, if your date field goes out of range, it returns -/-/- instead of valid values. Your database might have criteria set that only valid dates are acceptable. This might also happen if other values, like numerics, go out of range. In order to avoid this, you must check for out-of-range values in your program before you write them to the database. If a value is not valid, you can assign some default value to write for these out-of-range cases. This helps to preserve database integrity as well.

Additional Information

The manual of the LabVIEW Database Connectivity Toolkit can also be found at C:\<Program Files>\National Instruments\<LabVIEW version>\manuals in a machine with the toolkit installed.