我是Visual Studio的新手。我目前正在创建一个登录表单。
我有这个代码。
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
using (OdbcConnection connect = new OdbcConnection(connectionString))
{
connect.Open();
OdbcCommand cmd = new OdbcCommand("SELECT username, password FROM receptionist", connect);
OdbcDataReader reader = cmd.ExecuteReader();
if (username_login.Text == username && password_login.Text == password)
{
this.Hide();
MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
else
MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
connect.Close();
}
}
catch (OdbcException ex)
{
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
但是,每当我尝试输入用户名和密码时,都会出现一个错误,提示“配置系统初始化失败”。我只是想知道这是什么问题,我该如何解决?
请帮忙。
确保项目中的配置文件(如果是web则为web.config,如果是Windows则为app.config)以以下方式启动:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="YourProjectName.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
</configuration>
请注意,在configuration
元素内部,第一个孩子必须是configSections
元素。
在element的name
属性中section
,确保将其替换YourProjectName
为实际项目的名称。
我碰巧在一个类库项目中创建了一个Web服务,然后将配置文件复制(覆盖)(以进行端点配置)到我的Windows应用程序中,并且开始遇到同样的问题。我无意中搬走了configSections
。
它对我有用,希望对您有所帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句