我有這樣的代碼我在Windows CESQLEXCEPTION Connection.Open()在設備應用
運行查價機設備,但我上線
cmd.Connection.Open();
獲得SqlException
在連接問題字符串或在我的代碼的另一部分?
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 < 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;
}
}
異常:
System.Data.SqlClient.SqlException:在系統在System.Data.SqlClient.SqlInternalConnection.OnError SQLEXCEPTION在System.Data.SqlClient.SqlConnection.OnError()()。 Data.SqlClient.TdsParser.ThrowExceptionAndWarning()在System.Data.SqlClient.TdsParser.Connect()在System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()在System.Data.SqlClient.SqlInternalConnection..ctor()在System.Data .SqlClient.SqlConnection.Open()at DeviceApplication1.Form1.textBox1_KeyPress()at System.Windows.Forms.Control.OnKeyPress()at System.Windows.Forms.Control.WnProc()
什麼是例外的內容防火牆?請在這裏發佈。 – 2014-11-22 18:03:58
如果這是您使用的IP地址,我會假設連接失敗。您始終可以將完整的例外記錄到文本文件並通過電子郵件發送給您自己。 – 2014-11-22 18:12:32
你能發佈完整的異常消息嗎? – 2014-11-22 18:19:02