title: Stored Procedure Return Unique Identifier
body: <p>I have a question which has been frustrating me and I have googled and googled and can't find what I want.</p>
  
  <p>I have this SQL Server stored procedure, which works great and returns the unique identifier:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[mcd_AddLogin]
     @UserName         nvarchar(256),
     @Password         nvarchar(256),
     @UID              uniqueidentifier OUTPUT
  AS
  BEGIN
     IF( @UID IS NULL )
          SELECT @UID = NEWID()
     ELSE
     BEGIN
         IF( EXISTS( SELECT [USERNAME] FROM dbo.LoginPassing_Active) )
            RETURN -1
     END
  
  Declare @Active bit
  Declare @Exp_Date datetime
  Set @Active = 1
  Set @Exp_Date =  DATEADD(mi, 1, GETDATE())
  
  INSERT dbo.LoginPassing ([USERNAME], [PASSWORD], [ACTIVE], [EXP_DATE], [UID])
  VALUES (@UserName, @Password, @Active, @Exp_Date, @Uid)
  
  RETURN 0
  END
  </code></pre>
  
  <p>I am trying to use this in and ASP.NET application, and am getting the following error:</p>
  
  <blockquote>
    <p><em>Procedure or function 'mcd_AddLogin' expects parameter '@UID', which was not supplied.</em></p>
  </blockquote>
  
  <p>Below is the code in my ASP.Net application, can anyone help me solve what is going wrong, I'm sure its really simple and I have just missed a trick:</p>
  
  <pre><code>    Dim conSQL As New SqlConnection
      conSQL.ConnectionString = My.Settings.conSQL
      conSQL.Open()
  
      Dim comSQL As New SqlCommand
  
      comSQL.Connection = conSQL
      comSQL.CommandText = "mcd_AddLogin"
      comSQL.CommandType = CommandType.StoredProcedure
      comSQL.Parameters.Add("@Username", SqlDbType.NVarChar).Value = "username"
      comSQL.Parameters.Add("@Password", SqlDbType.NVarChar).Value = "password"
  
      comSQL.ExecuteNonQuery()
      litAD.Text = comSQL.Parameters("@UID").Value
  </code></pre>
  
  <p>Appreciate your help in advance.</p>
  
  <p>Thanks,
  Steve</p>