dj.canuk
dj.canuk

Reputation: 13

VB.net parameterized query uses sp_executesql but loses UTF8 characters

I have an odd scenario that I'm looking for some clarification on.

I currently have an VB.net application that is sending the parameterized query below to an SQL Server 2019 database using ADO.net. To make the database support UTF8, we are using one of the new _UTF8 collations. For this test, we are using a database configured to use Latin1_General_100_CI_AI_SC_UTF8.

Query:

exec sp_executesql 
   N'UPDATE Roles SET Name = @pName WHERE Role_ID = 6',
   N'@pName varchar(1000)',
   @pName='æææDeveloper'

Now, I know that when I run the query above in MSSQL Management Studio, I don't lose my 'æ' characters but if I run this through code, my characters are replaced by '?'. My question is why would I lose them through code via ADO.net and not through MSSQL Management Studio.

I also know that sp_executesql does not support varchar as parameters which was the main problem and we were able to solve but again. Why would it work in MSSQL but not in ADO.net?

Upvotes: 0

Views: 167

Answers (0)

Related Questions