Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Exception while changingpassword of current user

$
0
0

I want to allow the current user to change his password. I have a visual webpart which contains two textboxes: the "OldPasswordTextbox" and "NewPasswordTextbox", a button "save" and a label "Msg".

the ascx code:

<asp:TextBox ID="OldPasswordTextbox" runat="server" Width="220px"></asp:TextBox><asp:TextBox ID="NewPasswordTextbox" runat="server" Width="220px"></asp:TextBox><asp:Label ID="Msg" runat="server"></asp:Label><asp:Button ID="save" runat="server" Text="Enregistrer" Width="86px" OnClick="ChangePassword_OnClick" />

the c# code:

protected void ChangePassword_OnClick(object sender, EventArgs args)
        {
            SPUser CurrentUser = SPContext.Current.Web.CurrentUser;
            string _userName = CurrentUser.LoginName;
            MembershipUser u=null;
            try
            {
               u = System.Web.Security.Membership.GetUser(System.Web.HttpContext.Current.User.Identity.Name);
            }
            catch (HttpException e)
            {
                Response.Write(e.Message+ " "+e.StackTrace);
            }
            try
            {
                if (u.ChangePassword(OldPasswordTextbox.Text, NewPasswordTextbox.Text))
                {
                    Msg.Text = "Password changed.";
                }
                else
                {
                    Msg.Text = "Password change failed. Please re-enter your values and try again.";
                }
            }
            catch (Exception e)
            {
                Msg.Text = "An exception occurred: " + Server.HtmlEncode(e.Message) + ". Please re-enter your values and try again.";
            }
        }

I have this exception:

Unable to establish a connection to a SQL Server database.

to  à System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) à System.Web.DataAccess.SqlConnectionHelper.EnsureSqlExpressDBFile(String connectionString) à System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) à System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) à System.Web.Security.Membership.GetUser(String username) à SharePointServiceDirect.WPDetails.WPDetailsUserControl.ChangePassword_OnClick(Object sender, EventArgs args) 

SQL services are started, TCP / IP is enabled. I haven't understand the problem.

Please help me.

Tahnks.


Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>