2

Im trying to connect to a mysql database on my web server, but I keep getting:

Unable to find the requested .Net Framework Data Provider.  It may not be installed.

Im guessing that the ADO.NET connector is present because if I change my config to:

providerName="System.Data.SQLClient"

I get:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

My provider config is:

    <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         autogenerateschema="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
  </providers>

My Connection string is:

<add name="LocalMySqlServer"
     connectionString="Data Source=localhost;user id=web210-aaron;password=tester;database=web210-aaron;"
     providerName="System.Data.MySQLClient"/>

Im pretty sure this is correct, especially as if I run it from my local machine (changing the host to the server IP) it runs perfecly! Could someone please confirm that this is a correct connection string.

RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75
  • Did you add a reference to the assembly containing `System.Data.MySQLClient`? – jrummell Feb 29 '12 at 18:57
  • I might not be understanding your scenario, but when you change the provider name to System.Data.SQLClient, it is only showing that the SQL Server provider might be installed. That doesn't mean the MySQL provider is installed. – Mark Wilkins Feb 29 '12 at 18:58
  • @MarkWilkins I thought they were all part of the same ADO Connector? I did add a reference to the assembly on my local machine, but I cannot install it on the server... I don think anyway – RonnyKnoxville Feb 29 '12 at 19:14
  • I'm not sure quite what you mean by "ADO Connector", but the .NET data providers for those two competing database servers are probably not going to be in the same install package. You can install both of them certainly, but I would think it will always require two separate installation packages. – Mark Wilkins Feb 29 '12 at 19:27

2 Answers2

2

Im going to answer my own question, as this wasted 3 days of my life trying to configure this manually.

Situation

  • You have created an MVC3/razor (possibly other c#) application
  • You are using MySql.Data.MySqlClient to try to connect to your database
  • You are able to connect from an IDE like VS2010 from your local machine to either a local database or database on your server but unable to connect when the site is deployed
  • When you deploy your web site, you get this error: Unable to find the requested .Net Framework Data Provider. It may not be installed. When trying to reference the MySql database

The issue is that your site cannot find the reference to MySQL.Data.


Solution

There are several sections which need to be changed in your web.config file, such as dbproviderfactories and creating namespaces. These can be added manually, but it is far more simple to allow the tools to do it for you.

You will need to include the relevant dll's in your bin folder or better yet, use Visual Studio SP1 to create the relevant folder and references by right clicking on the project (there is an option there to create a bin folder containing all of your dlls). Ensure that MySql.Data.MySqlClient is contained in this folder, if it is not you should be able to drag it from your bin folder into the new one that has been created by VS.

You can then use nuGet package manager console to install BLToolKit. This will download any missing dlls, insert them into your folders and correctly reference them automatically. This way, you can deploy your MVC application to a web server where MySql.Data (or any other dll for that matter) may not be installed.

RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75
0

You need to first have this installed

http://dev.mysql.com/downloads/connector/net/1.0.html

And it is a different provider

http://dev.mysql.com/downloads/connector/net/#downloads

Then add your data source through Visual Studio and it will change the app.config for you

Craig Trombly
  • 464
  • 2
  • 9
  • I realise this. But I do not own the server and so cannot install anything on it. The connection string the help guys gave me is: `Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=web210-aaron;User=web210-aaron; Password=;Option=3;` Which obviously does not work – RonnyKnoxville Feb 29 '12 at 20:14
  • What happens when you run this locally in Visual Studio from the Debug menu? – Craig Trombly Mar 12 '12 at 19:10