In OnBase 24.1 and higher, Unity Scripts that make a connection to a SQL Server database using System.Data.SqlClient.SqlConnection will receive the following error:
An unhandled error occurred in a Unity Script.
Unable to cast object of type 'Microsoft.Data.SqlClient.SqlConnection' to type 'System.Data.SqlClient.SqlConnection'.
This issue occurs because, as of OnBase 24.1, the underlying type for a SQL Server database changed from System.Data.SqlClient.SqlConnection to Microsoft.Data.SqlClient.SqlConnection. This change explains why existing solutions using System.Data are throwing this conversion error.
To resolve this issue, update the connection type used within the script to DbConnection. The syntax for this is available in the API SDK. See Accessing Connection Strings and Configuration Items for details. The System.Data.dll must be added to the project as a reference and the System.Data.Common namespace must be added per Microsoft's documentation for DbConnection Class.