Error: Object cannot be cast from DBNull to other types.


Error: Object cannot be cast from DBNull to other types.

Description: An invalid cast exception, when trying to convert a nonexistent value of table column to other types.

Solution: Use DBNull.Value to validate the column having a valid value or not.


if (!DBNull.Value.Equals(row[FirstName]))
{
  return Convert.ToString(row[FirstName]);
}

Advertisements

Error: Unknown object type ” used in a CREATE, DROP, or ALTER statement.


Error: Unknown object type ” used in a CREATE, DROP, or ALTER statement.

Description: When we try to use an unknown type in SQL statements, the exception throws.

CREATE table1
(
name nvarchar(10)
)

Here the complete syntax is missing. CREATE is the object but the type is missing. SQL Server trying to use table1 as the object type instead of TABLE.

Solution: Use the complete correct syntax.

CREATE TABLE table1
(
name nvarchar(10)
)

CREATE FUNCTION func1
  RETURNS int....

Error: Column already has a DEFAULT bound to it. Could not create constraint.


Error: Column already has a DEFAULT bound to it. Could not create constraint.

Description: The constraint trying to create for the column is already exists.

Solution: From system table sys.objects find out the constraint, rename or drop the existing constraint and then create the new one.

SELECT
      name
      ,OBJECT_NAME(parent_object_id) AS ParentTable
      ,OBJECT_NAME(object_id) AS ConstraintName
FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'
order by name

Error: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.


Error: System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

Description: There can be many reason.

  1. The request to SQL Server or query is taking a long time to execute.
  2. The result is returning large amount of records.
  3. Slow network connection issue.
  4. SQL Command connection timeout is not configured properly.
  5. Badly made SQL statements

Solution:

  1. Check the network connectivity is up and running.
  2. Check the SQL Statements, if required tuned and optimize it.
  3. Check the result size.
  4. Configure Connection Timeout property, by default it’s 15 seconds.

Error: Cannot retrieve the column code page info from the OLE DB provider.


Error: [OLE DB Source [1]] Warning: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the “DefaultCodePage” property, the code page from that property will be used.  Change the value of the property if the current string code page values are incorrect.  If the component does not support the property, the code page from the component’s locale ID will be used.

Description: This is actually a warning not an error by OLE DB. This warning occurs in SSIS project while we do a data transfer from source (Oracle) to destination SQL Server via OLE DB. This is because for the Oracle database the default code page is missing due to this it leads to bad data conversions. SSIS supports the option of specifying a per-column Locale Identifier for string data types, such as CHARACTER. However, the OLE DB Provider for Oracle does not support this option.

Solution: We can overcome this OLE DB warning by changing the property of OLE DB Source Data Flow Component. That property is AlwaysUseDefaultCodePage, by default the value is False, change it to True. Rebuild the project.

Error: No valid Oracle clients found. You need at least one 64-bit client properly configured.


Error: No valid Oracle clients found. You need at least one 64-bit client properly configured.

Description:

This error occurs when we try to connect an Oracle database, through a Client like Toad for Oracle etc.. The error clearly says an 64-bit Oracle client need to be installed properly inorder to access the database.

Solution: Download and install Client from given link.
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

The required software link is “Instant Client for Microsoft Windows (x64)”.
http://www.oracle.com/technetwork/topics/winx64soft-089540.html

The latest version is Version 11.2.0.3.0, select the Instant Client Package – Basic Lite: Smaller version of the Basic, with only English error messages and Unicode, ASCII, and Western European character set support (10.2 only).

Unzip the files to your Oracle installation folder. e.g: C:/oracle or C:/oraclehome. So the client installation is completed.

Now the important part comes. We need to configure the client.

For that first set up the TNS_ADMIN environment variable and later confure the tnsnames.ora.

1. How to setup up the environment variables
Open the Control Panel –> click, System (Classic View) –> select, Advanced tab –>click, Environment Variables –> click, New (User variables) –> enter Variable Name as “TNS_ADMIN” and Variable Value as the location path of file “tnsnames.ora”, which comes in C:/oracle….Networ/Admin, now click, New (System variables) –> enter Variable Name as “Path” and Variable Value as the Oracle client folder path. If Variable Value already exists then append a semi-colon ; to the list and update the new path, then  Click OK.

2. Now open the “tnsnames.ora” and enter database configuration information.


OracleDatabaseName_Custom =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname or ipaddress)(PORT = portnum))
) (CONNECT_DATA =
(SID = XE) (SERVER = DEDICATED)
)
)

That’s it. Now open your client and access the database.