![](/img/trans.png)
[英]How to connect to the Remote Database using Connection String in C#.net
[英]C#.NET connection string cannot connect
我正在使用Visual C#Express 2008,并通过转到添加->新数据源创建了数据库和数据集。 我正在尝试向其中添加一条记录,但是无法使用向导中提供的数据字符串进行连接。 请帮忙。 这是我的代码
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();
由于您使用的是SQL Compact Edition数据库文件(.sdf),因此应使用Sql Ce Connection代替SqlConnection,如本其他文章中所述
通常,您需要在同一连接字符串中指定用户名和密码。 我知道您可以通过在连接字符串中使用integrated security=true
来使用Windows凭据进行连接,但是我认为在您的情况下,您可能希望使用Data Source=|DataDirectory|\\\\myLife.sdf;User id=Bob;Password=*******
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.