Membership and rolls through visual studios 2012 MySql - mysql

I am trying to set membership and rolls through visual studios 2012 using my live hosted MySQL database.
I have been following this tutorial .
After trying a few times, I am getting stuck on this one part where I run Web Site Administration Tool and keep getting the same error when I click on the security tab
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: Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=******'.*
My code is following
machine.config code
<membership>
<providers>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=*******" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
<add name="MySQLMembershipProvider" autogenerateschema="true" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=***********" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
web.config code
<connectionStrings>
<remove name ="LocalMySqlServer"/>
<add name="LocalMySqlServer"
connectionString="Datasource=000.000.00.000;Database=******;uid=******;pwd=*******;"
providerName="MySql.Data.MySqlClient"/>
I am not sure of what is the cause of this error. What i am missing here?

If you can run your application - just do it and see actual database related error. As for me it was not existing database. I manually created the database and only after that went on with "Web Site Administration Tool" successfully.
And check connection string format. My looks like
Server=localhost;Database=xxxx;Uid=yyyy;Pwd=zzzz;
Hope this helps

Related

"Could not load file or assembly 'MySql.Web" But I am not using MySQL?

I have an ASP.Net MVC 5 web site that is using Entity Framework and SQL for the database. When I publish the site to my host and run it I now get an error about MySql.Web.
Could not load file or assembly 'MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
The error message also focus on this line from the machine.config
<add name="MySQLMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider,
MySql.Web, Version=6.8.3.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d"
connectionStringName="LocalMySqlServer"
enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="true" applicationName="/"
requiresUniqueEmail="false" passwordFormat="Clear"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
I do not use MySql in my project and can not find any references to it in any of my configuration files.
I have read some other posts on SO that talk about adding the MySql connector to my configuration but don't understand why I would need to do that if I don't use MySql anywhere??
It looks like someone installed the MySQL Connector on your machine.
You should be able to remove providers from your app using a <clear/> or <remove name="MySQLMembershipProvider" /> in your web.config.

Using membership provider in MVC2 with MySQL

I've read several posts in this forum about this but nothing seems to work. I'm trying to replace the default SQL Server based providers with MySQL providers using the latest version of connector (6.3.6.0) and VS2010, but I keep getting an error when accessing the Security section in WSAT. Here are my steps:
1) create a new mysql database.
2) create a new MVC2 application.
3) change web.config as follows:
<connectionStrings>
<remove name="LocalMySqlServer"/>
<add name="LocalMySqlServer"
connectionString="Data Source=127.0.0.1;Port=3306;Database=Sample;User id=root;Password=mysql;"
providerName="MySql.Data.MySqlClient"/>
<remove name="ApplicationServices"/>
<add name="ApplicationServices"
connectionString="Data Source=127.0.0.1;Port=3306;Database=Sample;User id=root;Password=mysql;"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
...
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear/>
<add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
connectionStringName="MySqlMembershipConnection"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/"
autogenerateschema="true"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
name="MySqlProfileProvider"
applicationName="/"
connectionStringName="MySqlMembershipConnection"
autogenerateschema="true"/>
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
<providers>
<clear />
<add connectionStringName="MySqlMembershipConnection"
applicationName="/"
name="MySqlRoleProvider"
type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"/>
</providers>
</roleManager>
<machineKey validationKey="AutoGenerate" validation="SHA1"/>
When I run WSAT and click Security, I get this 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: The source was
not found, but some or all event logs
could not be searched. To create the
source, you need permission to read
all event logs to make sure that the
new source name is unique.
Inaccessible logs: Security.
Could anyone tell me what's wrong with this procedure? Thanks to all!
finally I got it working and I'd like to share the information here. I am using the latest version of Connector/Net (6.3.6) in an ASP.NET MVC 2 website. Here is what I did:
1) create a new MySql database (or just use yours if any).
2) ensure that your machine.config has enabled schema autogeneration for MySQLMembershpProvider. As you probably know, machine.config is typically placed under c:\windows\microsoft.net\framework[version]\config\machine.config. Find under the entry for MySQLMembershipProvider and append the attribute autogenerateschema="true" to the element . The whole element will look like this:
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" autogenerateschema="true"/>
3) in your web.config (I'm referring to a newly created web application, so make your changes if required) change the connection strings and providers so that they refer to MySql. Typically: under connectionStrings add:
<remove name="ApplicationServices"/>
<add name="ApplicationServices" connectionString=connectionString="server=YOURSERVER;UserId=YOURUSER;password=YOURPASSWORD;Persist Security Info=True;database=YOURDATABASE;charset=utf8" providerName="MySql.Data.MySqlClient"/>
(BTW, notice the charset=utf8 in the connection string: this is not required for membership, but it is required if you are going to use this connection string to exchange Unicode data: it is not enough to just define the character set in your MySql table fields!).
Also, under membership / providers... ensure that the membership provider element (typically something like add name="AspNetSqlMembershipProvider"...) connectionStringName attribute refers to the connection string you set above (in my case, connectionStringName="ApplicationServices"). Do the same for profile and roleManager providers, which should look like this:
<profile>
<providers>
<clear/>
<add type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
name="AspNetSqlProfileProvider"
applicationName="/"
connectionStringName="ApplicationServices"
autogenerateschema="true"/>
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
<providers>
<clear />
<add connectionStringName="ApplicationServices"
applicationName="/"
name="MySqlRoleProvider"
type="MySql.Web.Security.MySQLRoleProvider,MySql.Web,Version=6.3.6.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"/>
</providers>
</roleManager>
<machineKey validationKey="AutoGenerate" validation="SHA1"/>
(Note the SHA1 validation!).
4) launch WSAT from Visual Studio and let it configure your MySql database. It should create all the tables required and let you create users and assign roles. Beware of table names casing! With WSAT tables like myaspnet_Users (not myaspnet_users) are created, and this might lead to confusions (MySQL Workbench seems to be confused by this and will show you just 1 table if you have 2 tables with their names differing only by casing. Tools like Navicat seem smarter in this respect). It's best to let WSAT create its tables to avoid this fuss.
Finally, remember that if you are going to use my_aspnet... tables in some relationships, you must make sure you select the proper MySQL database engine, i.e. not MyISAM but InnoDB, otherwise your foreign keys even if set will be ignored.
That's all I can share for this issue. Hope this might save some hours to someone else...
Perhaps I found the culprit: the PC I was working today had not its machine.config (for .net 4) configuration set for autogenerateschema="true" (btw there is a typo in my code above, the connection string name is not correct, but this happened only by copy/paste in my post). So maybe this is useful for all the newcomers like me: remember to set autogenerateschema="true" in
Thanks anyway

MVC2 MySQL Hosting Issue?

I have an MVC2 app that utilizes MySql.Web ver. 6.2.2.0, on my dev machine locally it works fine!
However, once I upload it to my http://www.winhost.com account I get the following error:
Parser Error Message: Unable to initialize provider. Missing or incorrect schema.
Line 32: <clear/>
Line 33: <add name="MySqlMembershipProvider"
Line 34: type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web,
Version=6.2.2.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d"
Is there something I can do to get this going? Or am I at the mercy of my host?
here is my config:
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear/>
<add name="MySqlMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider,MySql.Web, Version=6.2.2.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"
connectionStringName="mysql"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/"
/>
</providers>
</membership>
Try these articles to help ensure your host, your MySQL instance, and your web app are configured correctly.
MySQL ASP.NET Membership and Role Provider
ASP.NET and MySQL - membership provider
Marvin Palmer has a great walkthrough on Implementing .NET Membership and Roles using MySql Connector
Another potentially related question.

MySQL Forms Authentication Hashed password problem

I am trying to use the ASP.NET forms authentication service with the MySQL connector version 6.3.2. I was able to get it working using cleartext passwords but unable to get hashed passwords working. Here is a snippet from my machine.config file
<system.web>
<membership defaultProvider="MySQLMembershipProvider">
<providers>
<add name="MySQLMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"
connectionStringName="LocalMySqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
</providers>
</membership>
</system.web>
I am using the ValidateUser method of the MembershipProvider class to perform authentication. If the line passwordFormat="Hashed" is changed to passwordFormat="Clear" users will authenticate. After changing settings in the machine.config file I remove all users and recreate the accounts. I inspected the contents of the aspnet tables and the passwords are being stored properly as hashes - just failing to verify.
Looks like I'm not the only one who has noticed this bug: http://forums.mysql.com/read.php?38,368612,372250. Easily fixed by adding the following to the web.config:
<system.web>
<machineKey validationKey="AutoGenerate" validation="SHA1" />
</system.web>

Unable to initialize provider. Missing or incorrect schema. for MySql.Web connector

I am trying to use MySql Connector 6.2.2.0 for membership and role providers.
The issue I'm having is: Unable to initialize provider. Missing or incorrect schema.
<authentication mode="Forms"/>
<roleManager defaultProvider="MySqlRoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<clear />
<add
name="MySqlRoleProvider"
type="MySql.Web.Security.MySQLRoleProvider, MySql.Web,
Version=6.2.2.0,Culture=neutral, PublicKeyToken=c5687fc88969c44d"
connectionStringName="mySQL"
applicationName="capcafe"
writeExceptionsToEventLog="true"
/>
</providers>
</roleManager>
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<add connectionStringName="mySQL"
applicationName="capcafe"
minRequiredPasswordLength="5"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
minRequiredNonalphanumericCharacters="0"
name="MySqlMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.2.2.0,
Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</membership>
Here is the line it doesn't seem to like:
Line 57: type="MySql.Web.Security.MySQLRoleProvider, MySql.Web,
Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
I have both MySql.Web and MySql.Data referenced and in my bin! Any help resolving this issue will be very much appreciated.
Add references to the assemblies, add autogenerateschema="true" attribute to both as:
<providers>
<remove name="MySQLProfileProvider"/>
<add name="MySQLProfileProvider" autogenerateschema="true" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/"/>
</providers>
use ASP.Net configuration tool.
I had this problem, it turned out there was no password in my connection string, I think checking carefully that your connection string is correct would be a good place to start.
My problem was I had "localhost" in my connection string instead of the IP address of the webhost's MySQL server.
Once I changed that in my web.config file it worked fine, so you need to check your web.config file very carefully.
I was experiencing this exact same issue. Mine ended up being a case issue since I was deploying my site to a linux server running Mono. Enabling autogenerateschema="true" helped me figure this one out. Some hosts won't let the code generate the necessary tables though, so if it doesn't auto-generate your schema then check out casing issues.
CodeMonkey's solution worked for me... I was actually deploying a new app to a Win 2008 Server VM. The schema could not be generated until I specified the LocalMySql connection string and set the MySQLRoleProvider autogenerate to true.