我正在尝试编写一个工具,它将跨多个数据库更新用户帐户凭据。这些数据库中的每一个基本上都支持同一应用程序的不同版本,因此每个数据库都具有相同的表名。我只对这些数据库中的一个名为 opususer 的表感兴趣。
我能够创建第一个 Linq to SQL 类并使用复选框列表创建选定项目的集合并将其发送到循环并更新用户凭据的方法。当我有一个 DataContext 时这很好用,但是当我向 SQL 类添加另一个 Linq 并尝试重新创建相同的东西时,除了在不同的数据库上我收到几个歧义错误和“成员被多次定义”错误。
我不明白 LinqToSQL 类指向一个完全不同的数据库,尽管表名是相同的,但是为什么这很重要,因为 datacontext 应该将它分开不?
我试过使用一个 DataContext 并添加一个别名,但我不确定这是否可以做到。我是 ASP.NET 的新手...
if (DatabaseName == "clincomm_243x")
{
using (UserAccountDataContext Data = new UserAccountDataContext()) // database clincomm_243x
{
string UserName = TextBoxUserName.Text.ToUpper();
opususer CheckUser = Data.opususers
.SingleOrDefault(opususer => opususer.username == UserName && opususer.active == true);
if (CheckUser == null || TextBoxUserName.Text.Length ==0)
{
TextBoxResult.Visible = true;
TextBoxResult.Text = "Username " + UserName + " does not exist. Please check and try again!";
}
else
{
TextBoxResult.Text = "";
TextBoxResult.Text = "User " + UserName + " has been found.";
TextBoxResult.Visible = true;
TextBoxResult.Visible = true;
TextBoxResult.Text += "\nAttempting to update user account details.....\n";
// Set the new values for the record returned
CheckUser.password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4";
CheckUser.hashtype_code = "SHA-256";
CheckUser.unsuccessfullogons = 0;
CheckUser.active = true;
DateTime newPasswordExpiryDate = DateTime.Now.Date.AddYears(10);
CheckUser.passwordexpirationdate = newPasswordExpiryDate;
Data.SubmitChanges();
TextBoxResult.Text += "\nUser Account " + UserName + " has been successfully updated\n";
TextBoxResult.Text += "\nPassword has now been set to 1234 and will not expire until " + newPasswordExpiryDate;
}
}
}