Skip to content

SqlConnection GetSchema("DataTypes") method returns wrong datatype for tinyint #36

@altrive

Description

@altrive

SqlConnection's method GetSchema("DataTypes") returns following results for "tinyint" data type

  • DataType: System.SByte
  • IsUnsigned:True

This result is inconsistent and it seems it should return System.Byte as DataType,
because SQLServer's tinyint data type is defined to be mapped to .NET byte type (0-254)
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings

Example code to reproduce problems

var conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=TestDB;Integrated Security=True;");
conn.Open();
var rows = conn.GetSchema(DbMetaDataCollectionNames.DataTypes)
                    .Rows
                    .OfType<DataRow>()
                    .Where(p=>(string)p["TypeName"]== "tinyint");
foreach (var row in rows)
{
	Console.WriteLine(String.Format("TypeName:{0,-25} DataType:{1,-30} IsUnsigned:{2,-15}",
	  row["TypeName"],
	  row["DataType"],
	  row["IsUnsigned"]
	));
}
//Output:
//TypeName:tinyint                   DataType:System.SByte                   IsUnsigned:True        

Root cause of problems

It seems SqlConnection GetSchema("DataTypes") method return results from following xml definition file.

https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/src/Resources/System.Data.SqlClient.SqlMetaData.xml#L804

Reproducible environments

I've confirmed this problem occurs following environments

  • .NET 4.6.1
  • .NET Core 2.0 with System.Data.SqlClient/4.4.0-preview2-25405-01

Note

It seems following issue mentioned this wrong tinyint datatype.
fsprojects/SQLProvider#69

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions