I'm getting this error when calling a stored procedure from .NET Entity Framework using Dapper.
Implicit conversion from data type sql_variant to varchar is not allowed.
The stored procedure parameter is @Name nvarchar(50) = NULL
.
So ideally, it should accept a null value. When I call the stored procedure and pass @Name = null
from .NET, I get gives this error.
This is the stored procedure:
CREATE PROCEDURE [dbo].[Member_Add]
@Id NVARCHAR(50) = NULL,
@Name NVARCHAR(50) = NULL
AS
BEGIN
INSERT INTO [dbo].Member (Id, Name)
VALUES (@Id, @Name)
END
Dapper was internally mapping object
to sql_variant
. When I pass null
it was considering it as object
type. As my stored procedure was expecting varchar
, sql_variant
was not convertible to it.
I started passing string.Empty
instead of null
object and it was working fine.
@Name = Request.Name??string.Empty;