sp_executesql processes uniqueidentifier-param with EntityCommandExecutionException but still acts like expected I use a Azure DB(MS-Sql) and administrate the DB with Management Studio for SQL Server 2016. My Application is a simple C#/WPF-Application.

So here we go, this is my SProc:

    ALTER PROCEDURE [dbo].[StartChangeTrackingProcedure]
(
@UID uniqueidentifier
)
AS
BEGIN
SET NOCOUNT ON
declare @sql nvarchar(max);

SET @sql = N'INSERT INTO TBL_ChangeTrackerPerLoggedUser 
             VALUES (0,0,0,0,0, @UID)';
             PRINT @sql;
EXECUTE sp_executesql @sql, '@UID uniqueidentifier', @UID = @UID
END


The TBL_ChangeTrackerPerLoggedUser's name is a bit confusing as it has nothing to do with the ordinary ChangeTracking-Mechanism, it is just a simple table where you can look up wether there were made any changes to DB or not (because Azure has no Query Notifications, right?). It looks like this:

CREATE TABLE [dbo].[TBL_ChangeTrackerPerLoggedUser](
[ChangedTemplates] [bit] NOT NULL,
[ChangedInstances] [bit] NOT NULL,
[ChangedWF] [bit] NOT NULL,
[ChangedUser] [bit] NOT NULL,
[ChangedDoc] [bit] NOT NULL,
[UserDependency] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_TBL_ChangeTrackerPerLoggedUser] PRIMARY KEY CLUSTERED 
(
[UserDependency] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)


Next you'll see the call from Entitiy Framework, where LoggedUser.Instance.UsrID is a GUID:

 using (NCDBEntities DBContext = new NCDBEntities())
 {
     var uid = new SqlParameter("@UID", LoggedUser.Instance.UsrID);
     var res = DBContext.Database
               .SqlQuery&lt;TBL_ChangeTrackerPerLoggedUser&gt;
               ("StartChangeTrackingProcedure @UID", uid).ToList();
 }


Now, when i process this code I get an EntityCommandExecutionException telling me:


  Der Datenleser ist mit dem angegebenen Wert für 'NCDBModel.TBL_ChangeTrackerPerLoggedUser' nicht kompatibel. Ein Element vom Typ ('ChangedTemplates') weist keine entsprechende Spalte im gleichnamigen Datenleser auf.


Translated this means something like: 


  Datareader is not compatible with the given value for 'NCDBModel.TBL_ChangeTrackerPerLoggedUser'. One element of type ('ChangedTemplates') has no actual column in equal named Datareader.


But when i take a look at DB at this point, SProc has been executed successfully:


So...is there any advice or explanation you can provide to understand this kind of magic? Should i simply catch this Exception and act like it never happened? Sideeffects etc.? Thank you!
You use an API that expects a result set (SqlQuery&lt;...&gt;(...)) but your stored procedure produces no result set. Hence the error message. The error occurs on the client side, after your procedure has executed, to explain the 'magic' you see.

You have several alternatives:


Use a non-query API, like ExecuteSqlCommand
have your stored procedure produce a result set, using the OUTPUT clause of INSERT.
Map the stored procedure in EF