title: Executing remote stored procedure within sp_executesql
body: <p>I'm trying to get IDENT_CURRENT value on the linked server.  I've created a stored procedure sp_current_identity on the remote server that has output parameter. </p>
  
  <pre><code>CREATE  PROCEDURE [dbo].[sp_current_identity] ( @strTableName nvarchar(255), @intRowId int OUTPUT )
  AS
  BEGIN
  select IDENT_CURRENT(@strTableName)
  END
  </code></pre>
  
  <p>After that I have created two synonyms:sp_current_identity and sometable.</p>
  
  <p>I need to execute sp_current_identity using sp_executesql (I'm creating a custom DataAtapter to work with synonyms via LLBLGEN 3.1). Please see the following example:</p>
  
  <pre><code>declare @p4 int
  set @p4=NULL
  exec sp_executesql N'SET XACT_ABORT ON; INSERT INTO [db].[dbo].[sometable] ([FieldName], [TableName], [UserField]) VALUES (@p1, @p3, @p4) ;
  exec dbo.sp_current_identity @p5, @p2 
  ;SET XACT_ABORT OFF',N'@p1 varchar(50),@p2 int output,@p3 varchar(50),@p4 varchar(50), @p5 varchar(200)',
  @p1='test24',@p2=@p4 output,@p3='test24',@p4='test5',@p5='sometable'
  select @p4
  </code></pre>
  
  <p>It works fine when  this code is executed on the remote server (where sp_current_identity is local stored procedure), but it causes an exception when the code is executed on the local server.
  Here is the error:</p>
  
  <p>Procedure or function 'sp_current_identity' expects parameter '@strTableName', which was not supplied.</p>
  
  <p>Thanks for your help! </p>