I have a stored procedure call in C#. It uses ADO.NET to call the stored procedure that is on my SQL Server. Despite knowing that one of the parameters of the stored procedure on the server is VARCHAR(120)
, I used AddWithValue
to add it to my parameter collection in C# and that has concluded that the string parameter used in C# should be translated to a SqlDbType
of NVARCHAR
. How do I tell if the server has used the NVARCHAR
type or the VARCHAR
type? I'm getting mixed messages regarding if ADO.NET is smart enough to read the correct parameter type from the server and I would like to test this empirically.
My current crude solution was as follows:
- Take a character that does not exist in
VARCHAR
, e.g.ǹ
i.e. 'Latin Small Letter N With Grave'. - Observe that SQL Server translates
SELECT ǹ
to?
. - Write a query that returns values when
?
is fed to it. - Feed said query
ǹ
. - Observe that the query has acted as if I fed it
?
. - Conclude that SQL has used
VARCHAR
even though I gave itNVARCHAR
.