如何在运行时使用Bltoolkit更改连接字符串

时间:2020-06-02 12:35:50

标签: c# bltoolkit

我正在使用“ Bltoolkit”访问sql服务器数据。根据我的要求,它可以正常工作。现在,我正在尝试在运行时更改连接字符串。我尝试了以下代码,但未更改连接,这表明它显示了默认的连接字符串。

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();
        }
    }

0 个答案:

没有答案