Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlCommand DeriveParameters should not return database in type name for table valued parameters #28335

Closed
ssa3512 opened this issue Jan 8, 2019 · 5 comments · Fixed by dotnet/corefx#35549

Comments

@ssa3512
Copy link

ssa3512 commented Jan 8, 2019

When using SqlCommandBuilder.DeriveParameters() which calls SqlCommand.DeriveParameters() the type name for the TVP in the derived parameters includes the database name which causes ExecuteNonQuery() to fail with the following exception:

System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Table-valued parameter 1 ("@DataTable"), row 0, column 0: Data type 0xF3 (user-defined table type) has a non-zero length database name specified.  Database name is not allowed with a table-valued parameter, only schema name and type name are valid.

In depth write-up and repro project here: ssa3512/DotNet_GetStoredProcCommand_TVP_Repro

https://github.com/dotnet/corefx/blob/875c9842c94fdf3885a7cd28497d492bdd584543/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs#L2212-L2214

@AfsanehR-zz
Copy link
Contributor

@ssa3512 Thank you for providing a repro, will investigate this issue and get back to you.

@Wraith2
Copy link
Contributor

Wraith2 commented Feb 14, 2019

@ssa3512 did you want to have a second pass at this after our discussion on the first PR I shall I pick it up?

@ssa3512
Copy link
Author

ssa3512 commented Feb 14, 2019

@Wraith2 I guess I am not sure what needs to be done to support it in a backward compatible way at this point. Additionally, I was unable to get a stable development environment up and running for corefx where I could run all the unit tests. If you have a fix please you can create a PR.

@Wraith2
Copy link
Contributor

Wraith2 commented Feb 17, 2019

I've almost got this written but something caught my attention in the code you posted, there's no escaping. If you used a type name which required the [ ] because it had a space for example that should generate an invalid name shouldn't it? something like dbo.Type With Space when it should be dbo.[Type With Space].

@ssa3512
Copy link
Author

ssa3512 commented Feb 18, 2019

I want to say that the names stored in r[colnames] are escaped before that point. I seem to remember seeing [] around the names when writing the workaround for this issue in my application.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants