martinjw/dbschemareader

DatabaseResultSet Column DataType Null Exception

Closed this issue · 2 comments

I am getting a null exception when I try to access a column's DataType from a storedprocedure resultset. Here is the code I'm using:

private static void TestSprocOutput(string dbConn)
        {
            using (var connection = new SqlConnection(dbConnectionString))
            {
                var dr = new DatabaseSchemaReader.DatabaseReader(connection);
                var schema = dr.ReadAll();
                var rsr = new ResultSetReader(schema);
                rsr.Execute(new SqlConnection(schema.ConnectionString));

                var proc = schema.StoredProcedures.FirstOrDefault(x => x.Name.Equals("ma_GetPeopleByName"));
                var rs = proc.ResultSets[0];

                foreach (var c in rs.Columns)
                {
                    Console.WriteLine(c.DataType.NetDataTypeCSharpName);    // DataType null exception!
                }
            }
        }

ResultSetReaderColumnProperty_NullException

Is this by design, a bug, or am I doing something incorrectly?

The column.DataType property is null, but the column.DbDataType (string property) has the name of the (.net) type.

I've just created a new version, 2.7.17, which will add the column.DataType property.

For stored procedures, there is no way of getting the original database type (eg varchar) for resultset columns, and I'm relying on the ADO provider to infer a .net type. So the DataType here is not the same as the schema.DataTypes used in tables, views and procedure arguments. In practice, complex procedure queries don't provide a lot of useful metadata typing (a varchar may not have a meaningful length), so use with caution, but a lot of things do work well.