gpt4 book ai didi

c# - "The ConnectionString property is invalid."当我知道它是有效的

转载 作者:行者123 更新时间:2023-11-30 20:11:02 28 4
gpt4 key购买 nike

我有一个 ASP.NET MVC 应用程序,其中的数据库位于 IBM i 系列服务器上。当我开始收到 The ConnectionString property is invalid. 错误时,我的应用程序开发接近完成:

  1. 仅在登录时
  2. 重建后首次成功登录后
  3. 任何登录的人仍然可以正常工作

另请注意,此问题仅出现在我的解决方案中的一个项目中。另一个项目使用完全相同的连接字符串并且没有这个问题(复制并粘贴以确保 100%)。我正在积极开发这些项目,但在登录后没有接触连接字符串,也没有使用 AccountController 和相关模型类。

我使用的是 Visual Studio 2008 和 .NET 3.5 版。

连接字符串:

<connectionStrings>
<add name="IbmIConnectionString" connectionString="DataSource=192.168.50.200;DefaultCollection=QMFILES;Naming=sql;UserID=XXX;Password=XXXX;"/>
</connectionStrings>

帐户 Controller 登录方法:

    [HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
string fullName = String.Empty;
string employeeId = String.Empty;

if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
EmployeeLoginModel elm = new EmployeeLoginModel();
elm.GetUserInfo(model.UserName, model.Password, out fullName, out employeeId);
// Update the AuthCookie to include the last 4 digits of the SSN.
string userDataString = String.Format("{0}|{1}|{2}", model.Password, fullName.Trim(), employeeId.Trim());
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(model.UserName, model.RememberMe);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString);
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(authCookie);

if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}

// If we got this far, something failed, redisplay form
return View(model);
}

员工登录模型:

public class EmployeeLoginModel
{
public string UserName { set; get; }
public string Password { set; get; }

private iDB2Connection conn;

/// <summary>
/// Initializes a new instance of the <see cref="EmployeeLoginModel"/> class.
/// </summary>
public EmployeeLoginModel()
{
conn = new iDB2Connection(ConfigurationManager.ConnectionStrings["IbmIConnectionString"].ConnectionString);
}

/// <summary>
/// Determines whether [is valid user] [the specified username].
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <returns>
/// <c>true</c> if [is valid user] [the specified username]; otherwise, <c>false</c>.
/// </returns>
public bool IsValidUser(string username, string password)
{
int count = 0;

// Get the data from the iSeries
using (conn)
{
string sqlStatement = "SELECT COUNT(XXXXX) FROM XXXXX WHERE UPPER(XXXXXX) = @1 AND XXXXXX = @2";

iDB2Command cmd = new iDB2Command(sqlStatement, conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@1", username.ToUpper());
cmd.Parameters.Add("@2", password);
conn.Open();
count = (Int32)cmd.ExecuteScalar();
conn.Close();
}

return ((count == 0) ? false : true);
}

最佳答案

出现此错误的另一个非常微不足道的原因是未安装所需的 DB2 驱动程序。

内部异常说明

Unable to load DLL 'cwbdc.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Type: System.DllNotFoundException

关于c# - "The ConnectionString property is invalid."当我知道它是有效的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4317514/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com