title: Why SQL query only works when running from VS but not outside
body: <p>I have a search textbox and a submit button, where the user can enter a name and hit the button to get a result. Only issue I am running into is when I run the website from VS, the query returns a result but when I make the website in to a web service
  and access it using the link outside of the localhost link, it doesn't work (displays <code>Failed: Not not found in Database</code>).</p>
  
  <p>My <code>localhost</code> link which works with search query: <code>http://localhost:53647/PDFFormsNew/searchcreate.aspx</code> (running through VS)</p>
  
  <p>My IIS link which I am accessing outside of VS which doesn't work for the search query: <code>http://devserver-svr-dev:85/searchcreate.aspx</code></p>
  
  <p>Any idea why it is causing it and how to fix it?</p>
  
  <p>I am including snippets of code which is doing the query:</p>
  
  <pre><code>string cString = "Data Source=svr-db;Initial Catalog=test-db;User Id=myusr;Password=p@$$w0rd;";
  protected void btnValidateName_Click(object sender, EventArgs e)
  {
      this.sqlQuery();
  }
  public void sqlQuery()
  {
      tc.Text = "HERE";
      Conn = new SqlConnection(cString);
      Conn.Open();
  
      //nameE = '%'+txtName.Text+'%';
      nameE = '%' + RemoveSpecialCharacters(txtName.Text) + '%';
      sqlCode = "SELECT * FROM [test-db].[dbo].[TablePDFTest] WHERE [name] LIKE @name"; //allow user to enter partial
  
      using (SqlCommand command = new SqlCommand(sqlCode, Conn))
      {
          //command.CommandType = CommandType.Text;
          command.Parameters.AddWithValue("name", nameE);
  
          using (reader = command.ExecuteReader())
          {
  
              if (reader.HasRows)
              {
                  rptContent.DataSource = reader;
                  rptContent.DataBind();
                  lblIsValid.Text = "Success: Name found in Database";
                  lblIsValid.ForeColor = System.Drawing.ColorTranslator.FromHtml("#009900");
                  //btnGeneratePDF.Visible = true;
              }
              if (!reader.HasRows)
              {
                  rptContent.DataSource = null;
                  rptContent.DataSourceID = null;
                  rptContent.DataBind();
                  lblIsValid.Text = "Failed: Name not found in Database";
                  lblIsValid.ForeColor = System.Drawing.ColorTranslator.FromHtml("#990000");
                  //btnGeneratePDF.Visible = false;
              }
          }
      }
  
      Conn.Close();
  }
  
  public static string RemoveSpecialCharacters(string str)
  {
      StringBuilder sb = new StringBuilder();
      foreach (char c in str)
      {
          if ((c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || c == '.')
          {
              sb.Append(c);
          }
      }
      return sb.ToString();
  }
  </code></pre>