user2009790 user2009790 - 2 years ago 98
MySQL Question / MySQL: Access denied for user ''@'localhost' (using password: NO)

I'm a web dev rookie and I'm hoping someone with more experience can help sort this out. I was ambushed by a MySQL upgrade.

I have two XP PCs (let's ambitiously call them "web server" and "MySQL server"). I recently built and successfully hosted an site that drew data from the MySQL db. It's just a site designed for a few local users so they don't have to learn SQL to get data...nothing fancy. So far so good.

This week I installed MySQL on the "web server", and that's when things went crazy. There had been no instance of MySQL on the web server before that point. Since the install I've:

  1. ...reinstalled the MySQL .NET provider

  2. ...reconfigured the machine.config file

  3. ...copied the MySQL_Web.dll to the MySQL bin directory

  4. ...attempted to get the setup to align with the directions in the site below.

This addressed a number of issues, and I got the site partially up and running again. I can access the landing page, and queries for guest users are returning data ok.

Error Message #1
However, when the user tries to log in to access private pages on the site, I get the error "Access denied for user ''@'localhost' (using password: NO)". This is clearly wrong since I'm using a password, and because there is no connection string pointing to the localhost/web server. The only connection string points to the MySQL server where the database resides.

Error Message #2
I'm also looking at the Web Site Administration Tool in the Security tab and seeing the following error:

"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store. The following message may help in diagnosing the problem: An exception occurred. Please check the Event Log."

The role manager is definitely enabled, and the providers are correctly set up.

I've tried uninstalling MySQL on the web server, recreating the site's user tables, flushing privileges and a few other tricks, but the site now seems to be permanently bypassing the db in the connection string during the log in process and searching the web server instead.

Does anyone have any ideas where I can take this next? I've been stumped for a few days, and I don't know what else I can do.

Edit: Supplying the relevant code as asked in the comments below. As noted, this is all standard code generated as part of a default project, and hasn't been edited in any way (except for web.config of course).


<remove name="MySQLWebConnection"/>
<add name="MySQLWebConnection" connectionString="server=myWebServer;User Id=myName;password=myPwd;database=myDB" providerName="MySql.Data.MySqlClient"/>

<membership defaultProvider="MySQLMembershipProvider" />
<roleManager enabled="true" defaultProvider="MySQLRoleProvider" />
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="~/Account/Login.aspx" defaultUrl="~/Default.aspx" />


<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
<div class="accountInfo">
<fieldset class="login">
<legend>Account Information</legend>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required."
<asp:CheckBox ID="RememberMe" runat="server" Visible="false" />
<asp:Label ID="RememberMeLabel" runat="server" Visible="false" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>

Answer Source

Solved. Hopefully this helps someone else with similar problems, and eases a few migraines along the way. A week of sheer panic left me seeking divine intervention when all else had failed, so the big guy upstairs gets the checkmark for this one. :)

Cause: Re-installing MySQL and the .NET connector meant the machine.config file customizations were overwritten.

Solution: After the updates, make sure the following two changes are in place in the machine.config file...


      <add name="MySQLMembershipProvider" **autogenerateschema="true"** ... />


  <add name="LocalMySqlServer" connectionString="server=dbServer;User Id=myUserID;password=myPassword;database=myDatabase" />

It was the second one that was tripping me up. During the reinstall the code had been changed to...

   <add name="LocalMySqlServer" connectionString="" />

...which is why the site was attempting to connect to the localhost, and why the user info in the web.config connectionstring was being ignored.

Good luck everyone! :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download