RickStrahl / Westwind.Globalization

Database driven resource localization for .NET applications
543 stars 135 forks source link

MySQL provider connectionString via code not working #97

Closed tomerpeled closed 7 years ago

tomerpeled commented 7 years ago

Hi,

I succeed to work with the MySQL provider while defining it via the web.config like this:

  <connectionStrings>
      <add name="Localization" connectionString="server=myserver;uid=myuser;pwd=mypassword;database=Localizations" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>

But when trying to override it via code it doesn't work:

DbResourceConfiguration.Current.ConnectionString = "server=myserver;uid=myuser;pwd=mypassword;database=Localizations"; 
            DbResourceConfiguration.Current.DbResourceDataManagerType = typeof(DbResourceMySqlDataManager);

Notice that when working with: DbResourceConfiguration.Current.ConnectionString = "Localization"; Instead of overriding the connectionString it works...

The SQL server provider is working in both scenarios (Config + override in code).

Anything I'm missing?

liviudragnoiu commented 7 years ago

ResourceSetLoadingFailed:Unable to cast object of type 'MySql.Data.MySqlClient.MySqlConnection' to type 'System.Data.SqlClient.SqlConnection'.

also from config doesn't work for me

RickStrahl commented 7 years ago

Please show your code...

liviudragnoiu commented 7 years ago

i have `

` and config ` ` also applied changes to global.asax file `protected void Application_Start() { DbResourceConfiguration.Current.DbResourceDataManagerType = typeof(DbResourceMySqlDataManager); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DbResourceConfiguration.Current.ConnectionString = "mySqlConnection"; DbResourceConfiguration.Current.DbResourceDataManagerType = typeof(DbResourceMySqlDataManager); } protected void Application_BeginRequest() { // Automatically set the user's locale to what the browser returns // and optionally only allow certain locales/locale-prefixes WebUtils.SetUserLocale(currencySymbol: "$", allowedLocales: "en,ro"); }` but still get the same error
liviudragnoiu commented 7 years ago

and conn string as <add name="mySqlConnection" connectionString="server=localhost;port=3306;user id=user;password=pwd;database=localizations" providerName="MySql.Data.MySqlClient" />

create table works but select insert doesn't

liviudragnoiu commented 7 years ago

do you have some limitations on mysql connectors or there is a bug? i cloned solution and did few debug and seems that data.executeReader gives null at first call but at second call i got some data. Where the issue can be?

liviudragnoiu commented 7 years ago

in my solution it seems to work without that default and force get provider from connString

@@ -54,7 +54,7 @@ namespace Westwind.Utilities.Data

endif

    public SqlDataAccess(string connectionString)
        : base(connectionString, SqlClientFactory.Instance)
        : base(connectionString)
    { }
RickStrahl commented 7 years ago

That code looks like it's hitting the SQL Server provider. Are you shure you're setting hte provider in the configuration?

If you are running the preview you might want to try this again with the beta. There were a lot of broken bits in the preview related to non-SQL server providers that have now been addressed. Make sure to re-read the configuration section for SQL providers.