IBM.Data.DB2.Core DataReader.GetSchemaTable() method throws NotSupportedException C# .NET standard

583 Views Asked by At

Code is in C# .NET standard

var connectionString = $"<connection string here>";
var connection = new DB2Connection(connectionString);
connection.Open();
IDbCommand command = connection.CreateCommand();
string sqlStatement = "<a valid query goes here>";
command.CommandText = sqlStatement;
IDataReader dataReader = command.ExecuteReader();

var data = new DataTable();
data = dataReader.GetSchemaTable(); //This throws a NotSupportedException.
//data.Load(dataReader); //This should work, but the above line is what throws the exception, which is what this method is calling internally.

A NotSupportedException is thrown on the last line that is not commented out, with the message 'Specified method is not supported.'

I have version 1.2.2.100 of IBM.Data.DB2.Core installed, and the version 11.1 license as well. If you need any more context let me know.

Thanks in advance.

1

There are 1 best solutions below

0
On

You query select dont have join, only one table.

I propose you my code which use IDB2 objects :

var connectionString = $"<connection string here>";
string sqlStatement = "<a valid query goes here>";

var connection = new DB2Connection(connectionString);
DB2Command myCommand = new DB2Command(sqlStatement,connection);

connection.Open();

try 
{
  DB2DataReader reader = myCommand.ExecuteReader(CommandBehavior.KeyInfo);

  DataTable dt = reader.GetSchemaTable();

  reader.Close();
}
finally 
{
  connection .Close();
}