title: "Specified cast is not valid" on SQL "OUTPUT" parameter
body: <p>I'm working on an ASP.NET site and have stumbled across an issue. I've been converting an ASP.NET Forum into ASP.NET 4.5. I've fixed everything and the site runs fantastic on my local dev machine. Once I upload it to my web host I get the following error. </p>
  
  <blockquote>
    <p>Server Error in '/' Application.</p>
    
    <p>Specified cast is not valid.</p>
  </blockquote>
  
  <p>I've been trying to figure it out and I am stumped. Here is the code, SQL table and the stored procedure.</p>
  
  <pre><code>    public static int GetWebIDAndFolder(string host, out string folder)
      {
          SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CrzyForumConnectionString"].ConnectionString);
          SqlCommand cmd = new SqlCommand("CWF_GetWebIDAndFolder", conn);
  
          host = host.Replace("www.", "");
  
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.Add("@WebDomain", SqlDbType.NVarChar, 50);
          cmd.Parameters.Add("@WebID", SqlDbType.Int, 4);
          cmd.Parameters.Add("@Folder", SqlDbType.NVarChar, 50);
          cmd.Parameters[0].Value = host;
          cmd.Parameters[1].Direction = ParameterDirection.Output;
          cmd.Parameters[2].Direction = ParameterDirection.Output;
  
          conn.Open();
          cmd.ExecuteNonQuery();
  
  
          int webID = (int)cmd.Parameters[1].Value;
  
          if (Convert.IsDBNull(cmd.Parameters[2].Value))
              folder = string.Empty;
          else
              folder = (string)cmd.Parameters[2].Value;
  
          conn.Close();
  
          return webID;
      }
  </code></pre>
  
  <p>SQL Table:</p>
  
  <pre><code>CREATE TABLE [dbo].[CWF_Webs] (
  [WebDomain] NVARCHAR (50) COLLATE Latin1_General_CI_AS NOT NULL,
  [WebID]     INT           NOT NULL,
  [Folder]    NVARCHAR (50) COLLATE Latin1_General_CI_AS NULL
  );
  </code></pre>
  
  <p>Stored Procedure</p>
  
  <pre><code>CREATE PROCEDURE [indie_world].CWF_GetWebIDAndFolder
  (
  @WebDomain  nvarchar(50),
  @WebID      int OUTPUT,
  @Folder     nvarchar(50) OUTPUT
  )
  AS
  
  SELECT @WebID = (SELECT WebID FROM CWF_Webs WHERE WebDomain = @WebDomain)
  SELECT @Folder = (SELECT Folder FROM CWF_Webs WHERE WebDomain = @WebDomain)
  </code></pre>
  
  <p>Any and all help will be appreciated. The code, table, and procedure are all from The project is from the following url. <a href="http://www.codeproject.com/Articles/4291/Riverside-Internet-Forums" rel="nofollow">http://www.codeproject.com/Articles/4291/Riverside-Internet-Forums</a>. It is the application im converting to base a simple forum off of and start expanding it.</p>