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

SqlClient: Allow specifying a UDT SqlParameter value via SqlBytes #28743

Closed
bricelam opened this issue Feb 20, 2019 · 3 comments · Fixed by dotnet/corefx#36678
Closed

SqlClient: Allow specifying a UDT SqlParameter value via SqlBytes #28743

bricelam opened this issue Feb 20, 2019 · 3 comments · Fixed by dotnet/corefx#36678
Labels
area-System.Data.SqlClient enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@bricelam
Copy link
Contributor

Today, it's possible to read a UDT value as a SqlBytes object from SqlDataReader using GetSqlBytes.

var connection = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB");
connection.Open();

var command = connection.CreateCommand();
command.CommandText = "SELECT geometry::Parse('POINT(0 0)')";

var reader = command.ExecuteReader();
reader.Read();
var geometrySqlBytes = reader.GetSqlBytes(0);

Unfortunately, there is no way to specify a UDT value as a SqlBytes object in SqlParamter.

var connection = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB");
connection.Open();

var command = connection.CreateCommand();
command.CommandText = "SELECT @Point.X";

var parameter = command.Parameters.AddWithValue("@Point", geometrySqlBytes);
parameter.SqlDbType = SqlDbType.Udt;
parameter.UdtTypeName = "geometry";

// ArgumentException: Specified type is not registered on the target server. SqlBytes
var x = command.ExecuteScalar();

SqlBytes should be special cased in this codepath as a means of merely specifying the bytes to send to the server.

cc @ajcvickers @divega

@AfsanehR-zz
Copy link
Contributor

Thanks @bricelam I can confirm that this is happening both in .Net Core and .Net Framework.

@saurabh500
Copy link
Contributor

@bricelam What is the use case for this? How will the bytes be constructed in the first place ?

@saurabh500
Copy link
Contributor

NVM I read through NetTopologySuite/NetTopologySuite#302

bricelam referenced this issue in NetTopologySuite/NetTopologySuite.IO.SqlServerBytes Sep 9, 2019
Direct users to take advantage of dotnet/corefx#35470
@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.
Labels
area-System.Data.SqlClient enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants