.Net and Mysql connection string

.Net and Mysql connection string

dynasoftdynasoft Posts: 446Questions: 69Answers: 3

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: Hi, can anyone point me to examples for the above as I can't find any. I keep getting error Unable to find the requested .Net Framework Data Provider. Many thanks.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Hi,
    Thanks. However I still get error 'Unable to find the requested .Net Framework Data Provider. It may not be installed.'. Are there drivers I need to install ? Conncting elsewhere in my code via ODBC works fine.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Bit of a basic question, but I assume you've downloaded the Editor package? Was this working for you before, or is this a new installation?

    Colin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Hi, yes its all there. My project is working fine with sqlserver but setting tings up for mysql won't work for editor. Works fine elsewhere in my code. The project was built so it supports sqlserver and mysql. Last bit is to make Editor work with mysql

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This is my connection settings for .NET and MySQL:

    colin@colin-dektop:/mnt/DataTablesSrc/extensions/Editor-NETCore-Demo/Editor NET Core demo/Properties$ cat launchSettings.json 
    {
      "$schema": "http://json.schemastore.org/launchsettings.json",
      "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
          "applicationUrl": "http://localhost:57111",
          "sslPort": 0
        }
      },
      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "launchUrl": "examples/index.html",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "DBTYPE": "mysql",
            "DBCONNECTION": "Server=127.0.0.1;Port=3306;Database=test;Uid=sa;Pwd=MyPASSWORD;"
          }
        },
        "Editor_NET_Core_demo": {
          "commandName": "Project",
          "launchBrowser": true,
          "launchUrl": "examples/index.html",
          "applicationUrl": "http://localhost:5000",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "DBTYPE": "mysql",
            "DBCONNECTION": "Server=127.0.0.1;Port=3306;Database=test;Uid=sa;Pwd=MyPASSWORD;"
          }
        }
      }
    }
    

    Could you take a look please and see if that's comparable to yours. We use .NET under Linux, but it should be the same.

    Colin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
    edited July 2021

    Thanks. My code is in a Model class as per below:

            public static DtResponse CRUDXxx(Int16 tpe, XxxUISettings lblo)
            {
                string strTp = string.Empty;
                Editor editor = null;
                NameValueViewModel[] arrNVVM = null;
    
                try
                {
                    HttpRequest formData = HttpContext.Current.Request;
    
                    arrNVVM = CommonAttributes.GetLogTypesViewModel();
    
                    using (Database db = new Database("mysql", "Server=127.0.0.1;Port=3306;Database=mydb;Uid=root;Pwd=mypswd;"))
                    {
                        editor = new Editor(db, "ProgrammeXxx").Model<XxxDBModel>();
                        editor.Field(new Field("id")
                            .Set(false)
                        );
                        editor.Field(new Field("EntryType")
                            .GetFormatter((val, host) => Array.Find(arrNVVM, o => 
                                o.Name == val).strValue)
                            .Set(false)
                        );
                        editor.Field(new Field("EntryDateTime")
                            .GetFormatter((val, data) => val)
                            .Set(false)
                        );
                        editor.TryCatch(false);
                        editor.Debug(true);
                        editor.Process(formData);
                    }
                    arrNVVM = null;
                    lblo = null;
                }
                catch (Exception ex)
                {
                    //...
                }
                return editor.Data();
            }
    

    Error ocurrs in the using line. Works fine with sqlserver. Thanks.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Adding a reference to the drivers to use does not fix the issue:

    using (Database db = new Database("mysql", "Driver={MySQL ODBC 5.3 ANSI Driver};Server=127.0.0.1;Port=3306;Database=mydb;Uid=root;Pwd=mypswd;"))

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
    edited July 2021

    I reference both MySqlConnector (1.2.1) and MySql.Data.dll (8.0.11). Could there be a conflict here?

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Please advise

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    When set for mysql the Database class will use MySql.Data.MySqlClient [reference.

    MySql.Data.dll I would have thought would be enough, but Driver={MySQL ODBC 5.3 ANSI Driver}; might be causing it issues. What if you drop that part?

    Allan

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Thanks. I initially did not have Driver={MySQL ODBC 5.3 ANSI Driver}; but it did not work either.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    What was the error without it, and does your project has a reference to the MySQL.Data library?

    Allan

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
    edited July 2021

    .Error was the same:

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

    MySql.Data.dll is referenced and in the bin folder

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    a reference to the MySQL.Data library

    MySql.Data.dll is referenced

    Is different case a problem?

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    I think Allan used 'MySQL.Data' in his reply. I have MySql.Data throughout and I just add the reference via the IDE so I don't think thats the issue.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Are you using .NET 5 / .NET Core or .NET Framework?

    If 5 or Core, you need to register the client - e.g. in Program.cs you might have (in Main):

    DbProviderFactories.RegisterFactory("System.Data.SqlClient", SqlClientFactory.Instance);
    

    Along with a using MySql.Data.MySqlClient; line.

    Allan

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    I use .Net fw 4.72 so I think from what I see DbProviderFactories does not expose RegisterFactory

    Adding the line using MySql.Data.MySqlClient; does not do anything

    Would you have anything else I can look out for? Thanks.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Also I don't use Entity Fw.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Passing "MySql.Data.MySqlClient" as 3rd paramter to Database method and in using produces same error msg.

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
    edited July 2021

    Adding to web.config:

    <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" />
    </DbProviderFactories>
    </system.data>

    Seems to work. Still testing..

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Adding that entry into web.config works well. Thanks.

Sign In or Register to comment.