i'm trying to use the GetColumnSchema method of the SqlDataReader class. But VS tells me that SqlDataReader does not contain a definition for GetColumnSchema. Do i miss a namespace or assembly reference?
My project is using .NET Framework 4.6.1
using System;
using DocuWare.LoggingNew;
using System.Data.SqlClient;
using System.Data;
using System.Xml.Linq;
using System.Linq;
using System.IO;
private void WriteSQLQueryOutputToTextFile(string DBUser, string DBUserPassword, string sqlQuery, string databaseName, string nameOfOutputFile)
{
StreamWriter outputFile = new StreamWriter(dWTestResult + "\\DatabaseUpgradeCheck\\" + nameOfOutputFile);
using (SqlConnection sqlCon = new SqlConnection("Data Source=" + GetEnvironmentVariable.MachineName + "; Initial Catalog=" + databaseName + "; User ID=" + DBUser + "; Password=" + DBUserPassword + ";"))
{
SqlCommand command = new SqlCommand(sqlQuery, sqlCon);
sqlCon.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
var columnSchema = reader.GetColumnSchema();
string header = string.Empty;
for (int i = 0; i < reader.FieldCount; i++)
{
header += $", {columnSchema[i].ColumnName}";
}
}
}
catch (Exception ex)
{
logger.Debug(ex, "Writing Database Output to the " + nameOfOutputFile + " file failed");
}
finally
{
reader.Close();
outputFile.Close();
sqlCon.Close();
}
}
}




GetColumnSchemais an extension inSystem.Data.Common. Are youusing System.Data.Common;?