c# - 如何使用 Bltoolkit 在运行时更改连接字符串
问题描述
我正在使用“Bltoolkit”来访问 sql server 数据。它按照我的要求工作正常。现在我正在尝试在运行时更改连接字符串。我尝试了下面的代码,但连接没有改变,这意味着它显示了默认连接字符串.
protected void LogIn_Clicked(object sender, EventArgs e)
{
DataTable Login = new DataTable();
string username = Request.Form["username"];
string password = Request.Form["password"];
bool remember = RememberMe.Checked;
DbManager.AddConnectionString(ConfigurationManager.ConnectionStrings["Default"].ConnectionString); // Default Connection String
using (DbManager Db = new DbManager())
{
Login = Db.SetCommand("Select * from UserList Where UserName = '" + username + "' And Password = '" + password + "' ").ExecuteDataTable();
if (Login.Rows.Count > 0)
{
Session["UserId"] = Login.Rows[0]["UserId"];
Session["UserName"] = Login.Rows[0]["UserName"];
Session["Division"] = Login.Rows[0]["Division"];
Db.SetCommand("UpDate UserList Set LoginTime = '" + Convert.ToDateTime(DateTime.Now).ToString("yyyy-MM-dd HH:mm") + "' Where UserId = " + Convert.ToInt16(Login.Rows[0]["UserId"]) + " ").ExecuteScalar();
DbManager.AddConnectionString(ConfigurationManager.AppSettings["GLD"]); // Changed Connection string from Web.Config File
Response.Redirect("~/Default.aspx");
}
else
{
ErrorMessage.Text = "Invalid UserName or Password";
ErrorMessage.Visible = true;
}
Db.Close();
Db.Dispose();
}
}
解决方案
推荐阅读
- google-chrome - Chrome 选项卡内存释放保留 cookie
- android - 从 jcenter 迁移到 maven 出现错误:“无法解决:org.adblockplus:adblock-android-webview:4.4.0”
- angularjs - 限制 AngularJS ng 风格
- postgresql - 有没有办法从 Postgres 数据库进行 API 调用?
- qt - 如何在 QML 中制作上滑/下滑动画?
- jquery - Spectrum.js 调色板在 UI 中无法正确显示
- xamarin - Xamarin 表单中是否有一个布局,可以根据他们的数量响应地显示它的孩子?
- react-native - 如何在 React Native Paper DataTable 中分页?
- android - 如果我在 putExtra 方法中更改我的包前缀名称,我的前台通知服务无法正常工作,为什么?
- javascript - 自动点击控制台中的某个键