title: SQL Server, Creation of Link server fail across a server
body: <p>I have a SQL Database that has a Stored Procedure that creates a link server to another server. </p>
  
  <pre><code>@password VARCHAR(MAX)
  
  IF NOT EXISTS (SELECT 1 from sys.servers where name = @sqlServerName)
  BEGIN
    EXEC sp_addlinkedserver @server = @sqlServerName, @srvproduct=N'SQL Server'
    EXEC sp_addlinkedsrvlogin          @rmtsrvname=@sqlServerName,
                                       @useself=N'False',
                                       @locallogin=NULL,
                                       @rmtuser=@username,
                                       @rmtpassword=@password
  END
  </code></pre>
  
  <p>I execute this Stored Procedure via Entity Framework like </p>
  
  <pre><code>var password = new SqlParameter("@password","password");
  
  Context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction,"usp_SpNamer @Inserts OUTPUT, @sqlDBName, @sqlServerName, @username, @password", inserts, sqldDBName, sqlServerName, username, password);
  </code></pre>
  
  <p>However, the creation of the Link server fails because the password is wrong. (The error is login failure)</p>
  
  <p>But this only happens when I run it via the bin/app.exe on a different server. if I run it via debug mode in VS, it works.</p>
  
  <p>Any obvious problems?</p>