SqlConnection conn = new SqlConnection("Data Source=192.168.0.0;Initial Catalog=DashReport;Integrated Security=SSPI; User ID=SA;Password=Admin@123;");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT STORE, YEAR,DATE FROM TOPSALES WHERE MONTH = " + txtcode.Text + ";";
// cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
DataTable dt = new DataTable();
if (dt.Rows.Count > 0)
gvDataGrid.DataSource = dt;
MessageBox.Show("No data found");
You cannot have both the integrated security and specify a specific user id and password at the same time. Since you have the
Integrated Security=SSPI;, that will take precedence and your connection tries to connect with the currently logged in Windows user.
Most likely, from a Windows CE device, you want to use the specific User I
string connStr = "Data Source=192.168.0.0;Initial Catalog=DashReport;User ID=SA;Password=Admin@123;" SqlConnection conn = new SqlConnection(connStr);
And another word of caution from long time SQL Server users, admins, and programmers: you should NEVER EVER use the built-in
sa account! Just don't do it - use another account (possibly one you create specifically for this application).