Connecting to a remote MySQL DB

Discussion in 'Databases' started by 5pence00, Oct 27, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have done the rounds and read a number of threads about connecting to a remote MySQL DB - sorry can't find an answer so here goes chaps...

    I'm using VS 2010 with connection string to mysql DB in web.config :

    <add name="lmsConnectionString" connectionString="server=70.32.105.214;User Id=****;database=****;password=****;Use Procedure Bodies=false;" providerName="MySql.Data.MySqlClient"/>


    On local machine all is well. On DASP server (@www.5pence.net) :
    Server Error in '/' Application.
    Unable to find the requested .Net Framework Data Provider. It may not be installed.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
    System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1402071
    System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactory() +67
    System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactorySecure() +22
    System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +11
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +117


    There is more at the base of the of the error stack though I believe it has something to do with connecting to the db.

    If someone could please help me I'll be most appreciative :)
    I really would prefer to use normal MS SQL DB (and I have that with DASP) - trouble is this connection is for a JoomlaLMS which uses the above MySQL

    Thankyou for your time.
    Spence
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Did you upload the mySQL connector dll to your application's bin dir?
     
  3. Thank you for your reply Bruce - I also created a support ticket and the sys admin said: It looks like your application configuration is missing some settings. You probably have to add the MySql provider in the list of database providers.

    I definitely have MySql.Data.dll in the bin directory.

    This is the first time I have had to connect to a MySQL DB and I just wish I could get it going.
    plus in web.config i have:
    <add name="lmsConnectionString" connectionString="server=70.32.105.214;User Id=****;database=****;password=****;Use Procedure Bodies=false;" providerName="MySql.Data.MySqlClient"/>

    So am I right in saying I also need to add the reference in my web.config as well? If so would it be like?:
    <configuration>
    <appSettings>
    <add key="lmsConnectionString" value="~/bin/MySql.Data.dll" />
    <appSettings>
    </configuration>

    Or am I barking up wrong tree?

    Thankyou for your reply
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    I created a test page that connect to a mysql database with MySQL .NET connector. It seems to be working ok.

    I recommend you create a real simple page to test if the component loads correctly.
     
  5. Thank you for your reply -

    I did what you suggested and I am more confused than I was when I began this journey. I created a simple grid, used a .NET MySQL Connector, again alls works fine on local machine, I load up to the server (remembering to add my dlls) and run and get this:

    Server Error in '/' Application.
    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Could not load type 'System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider'.

    <add extension=".exclude" type="System.Web.Compilation.IgnoreFileBuildProvider" />
    Line 139: <add extension=".refresh" type="System.Web.Compilation.IgnoreFileBuildProvider" />
    Line 140: <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
    Line 141: <add extension=".xoml" type="System.ServiceModel.Activation.WorkflowServiceBuildProvider, System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    Line 142: <add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    EntityProvider... I'm not using even using it.


    So then just for sanity's sake I create a new empty website with no connectors - just a default page with text and web.config. Upload to server and ... I get the same result as above.



    Thanks - Spence
     
  6. Forget the above post = I deleted everything I could in ftp and re-uploaded - got the simple text site working, now I am back to the issue of MySQL connector/driver.
     
  7. Well, thank you for tryig to help - I have tried to make an simple page work and I still have the same issue.

    I look in my bin directory and see MySql.Data.dll in there and I have tired a number of different setting in my web.config - currently it stands at:

    <connectionStrings>
    <add name="lmsConnectionString" connectionString="server=70.32.105.214;User Id=***;database=lms;password=***;Use Procedure Bodies=false;"
    providerName="bin/MySql.Data.dll" />
    </connectionStrings>

    and I keep getting teh same results:

    [ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
    System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1402071
    System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactory() +67

    Is there anyone there I can pay to get this working?
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    I don't think you can connect to mysql like this.

    You are defining the provider name in the connection string.

    Here's the sample code i used

    <%@ import namespace="System.Data" %>
    <%@ import namespace="MySql.data.MySqlclient" %>
    <%@ import namespace="MySql.data.MySqlclient.MySqlConnection" %>
    <Script runat="server">
    Sub page_load()
    Dim dbconn As MySqlConnection
    Dim dbCMD As MySqlCommand
    Dim dtr As MySqldatareader
    dbconn = New MySqlConnection("server=MySQL Server;database=DBName;user=DBLogin;port=3306;password=DBpassword;")
    dbconn.open()
    dbCMD = New Mysqlcommand("select * from tblContact", dbconn)
    dtr = dbCMD.executereader()
    While dtr.read()
    Response.Write("<li>")
    Response.Write(dtr("FName") & "---" & dtr("LName"))
    End While
    dtr.close()
    dbconn.close()
    End Sub
    </Script>
     
  9. Actually, you can specify the MySQL provider name in the connection string, but you will need to add "MySql.Data.MySqlClient" to the list of DbProviderFactories.

    In your application web.config, try adding the following. Verify the Version and PublicKeyToken from the MySql.Data.dll that you are using. If you installed the MySQL connector on your computer, you can also see this same configuration on your computer's machine.config.

    Code:
    <configuration>
        <system.data>
            <DbProviderFactories>
               <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
            </DbProviderFactories>
        </system.data>
    </configuration>
    
     
  10. Thankyou for your reply A.

    I have added that into my web.config - still the same rwesults however I believe there may be a problem with my MySql.Data.dll

    When I look in the machine.config for this I am .net framework 4/config folder i find:
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
    description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />


    when i look at the properties of the MySql.Data.dll I find file version is 6.0.2.0 - which incidentally I cannot find anywhere in any .NET machine.config

    My bin folder has the MySql.Data.dll that refers to the 6.0.2.0 version.

    I changed the version number within my web.config file and still get same results.

    Some guys from expert exchange are interested in the outcome as some of them have looked into the problem and got as far as I have.

    I will save everything and strip back everything to just a grid and a odbc to see if I can get just that working.
     
  11. I cannot get this working dispite your advice. I have asked 2 experts from Experts exchnge to try this and both have been unable. It is therefore with great regret that I will be off to find an alternative provider and update the community at EE of my support experiences here.

    Thank you DASP staff Bruce and Lucas for trying to help me on this forum.
     
  12. Bruce

    Bruce DiscountASP.NET Staff

    Sorry to hear that you are leaving. Good luck and keep us in mind for your other .net projects.
     
  13. I have promised some people at EE that I would try to reach this conclusion on connecting to the external MySql DB as a guy in the EE community has said:

    I'm more curious to see what your ISP says is the way to implement MySQL.

    I saw in your code ou have a path to the MySQL.dll specified. Would be nice to know if the path is correct according to your ISP.

    Your code would be informative as well as any information your ISP gives for do-it-yourselfers.

    So could you give me idiot instructions on how to set up a link to an external MySql DB. I would like to use the VS 2010 .NET SqlDataSource tool in the toolbox to set the connection up.

    As far as I am aware I have set the connection in my web.config, added the MySql.Data.dll to the bin directory and can confirm everything on my desktop works.
     
  14. If to re-capp - still on this on-going problem....

    I am now re-installing windows and starting from a fresh install of VS2010 and MySQL Connector 6.3.5

    The problem is the MySQL connector - my machine config DOES NOT match the MySql.Data.dll version - When I uploaded MySQL Connector 6.3.5 and installed it I saw the details in my machine.config file but when i then searched everywhere MySql.Data.dll there was not one on my machine...

    Any ideas?
     
  15. MySQL with ASP.NET 4

    Here's my solution after pulling my hair out for a few days.

    I am using VS2010
    I have MySQL Connector v 6.3.5

    What you need to do is the following:

    1. copy all dlls to your bin directory because they are not installed on DASP.net

    2. copy what's on your machine.config file to your web.config file
    on my machine it looks like this:
    <system.data>
    <DbProviderFactories>
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
    </system.data>

    ***important*** if you enter this in, your project in VS2010 will not work properly. Once you have this in place and replace it on DASP.net, then you can take it out so it can work. Alternatively you can do a transform in your Web.Debug.config or Web.Release.config (However I have not done that yet)

    It should be that simple. (Thanks for nothing Tech support!)

    Hope this helps.
     
  16. Do you guys have troubles with MySQL connector in general or with connection to outside mysql db?

    Anyway I use dasp MysQL db and connect fairly easy, just copy mysql dll to output directory and in your own project reference it by file, not by a link to GAC assembly. If I misunderstand something and this issue only happens with outside MySQL connection (which is doubtful) then I misunderstood and my advice is worthless.

    I didnt edit anything in web.config to make it work.
     
  17. Bruce

    Bruce DiscountASP.NET Staff

    We also did some internal testing w/ mySQL connector by bin deploying the dll and it worked great.

    We didn't install the dll on the server because mySQL connector changes too frequently. They released at least 4 versions within the last 6 months.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page