Sqlclient: SqlConnection.GetSchema cannot get procedure parameters with predefined metadata collection name

Created on 22 May 2020  路  5Comments  路  Source: dotnet/SqlClient

Description

I tried to get parameters of sql server procedure, so I used GetSchema method as follow:
DataTable dt = connection.GetSchema(SqlClientMetaDataCollectionNames.Parameters);
Then I got an exception telling me the requested collection(Parameters) is not defined.
I am confused because I have already tried collections like Databases/Tables/Procedures/Columns and the collection name is predefined by SqlClientMetaDataCollectionNames class.

Configuration

I am using System.Data.SqlClient 4.8.1 from nuget with project configured as .Net Framework 4.7.

Other information

I reviewed some codes in System.Data and found that this collection name string is both 'ProcedureParameters' in OLEDB and ODBC connection.
So I tried to type 'ProcedureParameters' string straight as parameter of GetSchema and it worked.
DataTable dt = connection.GetSchema("ProcedureParameters");
I think it's a minor bug that you can fix it by updating string mapping in SqlClientMetaDataCollectionNames.cs

Most helpful comment

@mizulily , I also test it with some old SQL Servers such as 2008, 2012, and 2016. All of them give me the same exception to this SqlClientMetaDataCollectionNames.Parameters.
This will be fixed soon for sure.

All 5 comments

/cc @cheenamalhotra

HI @mizulily,

I quickly checked the Microsoft.Data.SqlClient and found that there is a missing string for "ProcedureParameters" in SqlClientMetaDataCollectionNames.cs . Looks like it's the reason for this issue.

Good catch 馃憤

Thanks,

HI @karinazhou ,
Yes, I think "ProcedureParameters" is missing in SqlClientMetaDataCollectionNames.cs
Furthermore, the predefined string "Parameters" is invalid since it will cause exception.

@mizulily , I also test it with some old SQL Servers such as 2008, 2012, and 2016. All of them give me the same exception to this SqlClientMetaDataCollectionNames.Parameters.
This will be fixed soon for sure.

Closing as #580 got merged.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crntn picture crntn  路  6Comments

amitagrawalhyd picture amitagrawalhyd  路  4Comments

agilenut picture agilenut  路  7Comments

MartinHBA picture MartinHBA  路  9Comments

jeroen-mostert picture jeroen-mostert  路  7Comments