Skip to content Skip to sidebar Skip to footer

Odbc Connect To Sql Server 2016 With Error Unknown Data Type -155

I've searched throughout the site and found the similar issue but with python not C#. Moreover, the workaround in that post (to avoid querying columns with DateTimeOffset datatype)

Solution 1:

Don't use ODBC. Use the classes in System.Data.SqlClient for SQL Server and ODP.NET for Oracle. The classes in both namespaces implements the corresponding interfaces in the System.Data namespace - so you can work with them the same - all you need is one simple factory that will return either the SQLClient implementation or the ODP.NET implementation of whatever interface you need to work with - something like this:

publicenum rdbmsTypes
{
    SQLServer,
    Oracle
}

publicclassADONetFactory
{
    private rdbmsTypes _dbType;
    privatestring _connectionString;
    publicADONetFactory (rdbmsTypes dbType, string connectionString)
    {
        _dbType = dbType;
        _connectionString = connectionString;
    }

    public System.Data.IDbConnection GetConnecion()
    {
        switch(_dbType)
        {
            case rdbmsTypes.SQLServer:
                returnnew System.Data.SqlClient.SqlConnection(_connectionString);
            case rdbmsTypes.Oracle:
                returnnew Oracle.DataAccess.Client.OracleConnection(_connectionString);
        }
        ThrowNotSupportedException();
    }

    public System.Data.IDbCommand GetCommand()
    {
        switch (_dbType)
        {
            case rdbmsTypes.SQLServer:
                returnnew System.Data.SqlClient.SqlCommand();
            case rdbmsTypes.Oracle:
                returnnew Oracle.DataAccess.Client.OracleCommand();
        }
        ThrowNotSupportedException();
    }

    privatevoidThrowNotSupportedException()
    {
        thrownew NotSupportedException("The RDBMS type " + Enum.GetName(typeof(rdbmsTypes), _dbType) + " is not supported"); 
    }
}

Then you should have built in support for all data types in both databases.

Post a Comment for "Odbc Connect To Sql Server 2016 With Error Unknown Data Type -155"