Jobin Joseph Jobin Joseph - 1 year ago 145
C# Question

SQL Exception in Windows CE device

Error MessageI'm working on Windows CE application, I was trying to connect to server database from the device and fetch some information from db on button click, below is the code I tried,

SqlConnection conn = new SqlConnection("Data Source=;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");


but while running the application I'm getting a
. It seems there is something wrong with the connection string. What is the right method to do it?

Answer Source

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=;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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download