MySQL Forums
Forum List  »  MySQL for Visual Studio

Re: MySQL for Visual Studio 1.1.1 Beta available for download
Posted by: Matt Hunter
Date: December 05, 2013 12:47PM

Hi Gabriella,

Is it possible to do this provider configuration in code? I have an EF6 project that is currently working properly with MSSQL that we would like to also try out with MySQL.

For the MSSQL configuration we have nothing in web.config and have a class that extends DbConfiguration. For the MSSQL config we are doing:

this.SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);

I poked around looking for the MySQL equivalent and came up with:

MySqlConnectionFactory cf = new MySqlConnectionFactory();
DbConnection mySqlConnection = cf.CreateConnection("Server=server;Database=database;Uid=username;Pwd=password;");
this.SetProviderServices(MySqlProviderInvariantName.ProviderName, MySqlProviderServices.GetProviderServices(mySqlConnection));


When I try to run the app I get the following exception when the SetProviderService method is hit:

System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.

The seemingly relevant parts of the stack trace are as follows:

System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Data.Entity.Utilities.TypeExtensions.CreateInstance(Type type, Func`2 exceptionFactory) +171
System.Data.Entity.Utilities.TypeExtensions.CreateInstance(Type type, Func`3 typeMessageFactory, Func`2 exceptionFactory) +154
System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1() +68
System.Lazy`1.CreateValue() +415
System.Lazy`1.LazyInitValue() +152
System.Lazy`1.get_Value() +75
System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration() +207
System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) +54

I'm sure I'm doing something wrong. Do you have any thoughts?

Thank you!



Edited 2 time(s). Last edit at 12/05/2013 01:03PM by Matt Hunter.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: MySQL for Visual Studio 1.1.1 Beta available for download
1976
December 05, 2013 12:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.