【发布时间】:2013-09-27 21:40:37
【问题描述】:
在窗口应用程序中,我正在尝试使用数据库,如何在 app.config 中编写连接字符串。下面是app.config中的连接字符串
<configuration>
<appSettings >
<add key ="mycon"
value ="server=192*****;database=*****;
uid=**;pwd=*****;"/>
</appSettings>
</configuration>
连接数据库的代码:
SqlConnection con = new SqlConnection(
ConfigurationSettings.AppSettings["mycon"].ToString()); con.Open();
SqlCommand cmd = new SqlCommand("Usp_chat_login", con);
cmd.CommandType = CommandType.StoredProcedure ;
cmd.Parameters.Add("@userid", SqlDbType.VarChar, 20);
cmd.Parameters["@userid"].Value = textBox1.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 20);
cmd.Parameters["@password"].Value = textBox2.Text;
int reslt = cmd.ExecuteNonQuery(); con.Close();
if (reslt > 0)
{
MessageBox.Show("Yes");
}
else
{
MessageBox.Show("No");
}
每次我收到reslt=-1,即使我通过了正确的凭据
【问题讨论】:
-
您存储的是纯文本密码,不是吗?仅限20个字符? /掌脸
-
如何在win app中存储和访问连接字符串stackoverflow.com/questions/8476103/…
标签: c# sql-server wpf winforms