问题
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.
Background: I have two XP PCs (let's ambitiously call them "web server" and "MySQL server"). I recently built and successfully hosted an asp.net 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.
Problem: 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:
- ...reinstalled the MySQL .NET provider
- ...reconfigured the machine.config file
- ...copied the MySQL_Web.dll to the MySQL bin directory
- ...attempted to get the setup to align with the directions in the site below.
http://dev.mysql.com/doc/refman/5.0/en/connector-net-tutorials-asp-roles.html
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 asp.net 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).
Web.config
<connectionStrings>
<remove name="MySQLWebConnection"/>
<add name="MySQLWebConnection" connectionString="server=myWebServer;User Id=myName;password=myPwd;database=myDB" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
<system.web>
<membership defaultProvider="MySQLMembershipProvider" />
<roleManager enabled="true" defaultProvider="MySQLRoleProvider" />
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="~/Account/Login.aspx" defaultUrl="~/Default.aspx" />
</authentication>
...
</system.web>
Login.aspx
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="LoginUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="login">
<legend>Account Information</legend>
<p>
<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."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<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."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<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>
</fieldset>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
</p>
</div>
</LayoutTemplate>
</asp:Login>
回答1:
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...
(1)
<membership>
<providers>
<add name="MySQLMembershipProvider" **autogenerateschema="true"** ... />
</providers>
</membership>
(2)
<connectionStrings>
<add name="LocalMySqlServer" connectionString="server=dbServer;User Id=myUserID;password=myPassword;database=myDatabase" />
</connectionStrings>
It was the second one that was tripping me up. During the reinstall the code had been changed to...
<connectionStrings>
<add name="LocalMySqlServer" connectionString="" />
</connectionStrings>
...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.
来源:https://stackoverflow.com/questions/15554290/asp-net-mysql-access-denied-for-user-localhost-using-password-no