tags:

views:

61

answers:

1

I'm using Visual C# Express 2008 and created a database and dataset by going to Add->New Data Source. I'm trying to add a record to it but cannot connect using the data string provided in the wizard. Please help. Here is my code

System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("Data Source=|DataDirectory|\\myLife.sdf;Password=*******");

System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT profiles (profile, file) VALUES ('here', 'here')";
cmd.Connection = sqlConnection1;

sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
A: 

Normally, you need to specify the username and the password in the same connection string. I know that you can use your windows credentials to connect by using integrated security=true in the connection string, but I think that in your case, you probably want to use Data Source=|DataDirectory|\\myLife.sdf;User id=Bob;Password=*******

Rice Flour Cookies
A good site for building your connection strings is... http://connectionstrings.com/
Patrick
I'm not sure that SQL Server CE supports user-level logon security, but, I believe, the DB itself can be password protected.
Steven