title: SqlException Connection.Open() in Device Application
body: <p>I have this code for my price checker device running on Windows CE</p>
  
  <p>But I get a <code>SqlException</code> on the line</p>
  
  <pre><code>cmd.Connection.Open();
  </code></pre>
  
  <p>Is the problem in the connection string or in another part of my code?</p>
  
  <pre><code>constring = "Password=12345;Persist Security Info=True;User ID=sa;Initial Catalog=Retail;Data Source=111.111.111.111";
  
  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  {
      if (e.KeyChar == (char)Keys.Enter)
      {
          for (int i = 0; i &lt; textBox1.Text.Length; i++)
          {
              if (char.IsDigit(textBox1.Text, 0) == false)
              {
                  MessageBox.Show("Invalid Barcode");
                  textBox1.Focus();
              }
              else
              {
                  try
                  {
                      Sql = "Select i.a_name,u.retailprice From sys_item i,sys_item_units u where i.itemean =u.itemean and u.barcode='" + textBox1.Text + "'";
                      cmd = new SqlCommand(Sql, new SqlConnection(constring));
                      da = new SqlDataAdapter(Sql, constring);
                      cmd.Connection.Open();
  
                      dr = cmd.ExecuteReader();
  
                      while (dr.Read())
                      {
                          label1.Text = dr[0].ToString();
                          label2.Text = dr[1].ToString();
                      }
  
                      cmd.Connection.Close();
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.Message);
                      textBox1.Text = "";
                      textBox1.Focus();
                  }
              }
          }
  
          e.Handled = true;
      }
  }
  </code></pre>
  
  <p>the Exception :</p>
  
  <p>System.Data.SqlClient.SqlException: SqlException at System.Data.SqlClient.SqlConnection.OnError() at System.Data.SqlClient.SqlInternalConnection.OnError() at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Connect() at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin() at System.Data.SqlClient.SqlInternalConnection..ctor() at System.Data.SqlClient.SqlConnection.Open() at DeviceApplication1.Form1.textBox1_KeyPress() at System.Windows.Forms.Control.OnKeyPress() at System.Windows.Forms.Control.WnProc()</p>