Connecting to MySql on Docker - mysql

I have an ASP.NET 5 Web API application which I have deployed on docker. It connects to a MySql instance, also on docker. I am using Entity Framework 6 to connect to the MySql database. I have not referenced Entity Framework directly, but am using the MySql.Data.Entity package which internally uses Entity Framework 6.
When I invoke the API, I get this error:
Unable to determine the provider name for provider factory of type 'MySql.Data.MySqlClient.MySqlClientFactory'
Outside docker, i.e., on my windows machine, in Visual Studio 2015, I point my web API to the MySql instance on docker, and I can connect just fine. Inside docker, I get the error mentioned above.
What could be wrong?

The provider name is not being passed. Prior to ASP.NET 5 the provider value could be set alongside connectionString in in the web.config. This is no longer the case, as the connection string is just a string value in a json file with no extra properties.
You need to set it programatically. Here's an example, notably this part;
SetProviderServices("MySql.Data.MySqlClient", new MySqlProviderServices());

I'm not an expert on ASP.NET, but doesn't your question translate to:
If I run ASP.NET on Windows everything works fine, if I run it on
Linux I get an exception.
?
I don't think this is a Docker issue and would rather investigate about issues / driver needs the Entity Framework has on Mono.

Related

How to connect to MySql using Entity Framework 6 from an ASP.NET 5 Web API application?

I have a Web API project created in ASP.NET 5 which uses the dnx451 framework. The project uses Entity Framework 6.1.3 and MySql .NET connector (MySql.Data.Entity) version 6.9.7 to connect to a MySql database.
Since there is no web.config, I need to use code based configuration to connect to the database. But I have run up against problems here.
I have a DbConfiguration implementation to handle the configuration. I followed the example mentioned here: http://dan.cx/2015/08/entity-framework-6-mysql-aspnet
However, I get a compilation error at this line:
        var dataSet = (DataSet)ConfigurationManager.GetSection("system.data");
The error is:
"Using the generic type 'ConfigurationManager' requires 1 type arguments".
Not sure what type argument I should pass in there.
I found it ! Just import "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final" in your project.json ;)

SQL adapter in Worlight?

I am new to IBM Worklight,and i found a way to connect to the MySQL using the SQL adapter.
the configuration as below:
<dataSourceDefinition>
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://localhost:3306/worklight_training</url>
<user>Worklight</user>
<password>Worklight</password>
</dataSourceDefinition>
Since the adapter are compile together with the app, just wondering, is it safe? is there a possibility of someone decompiling my apk or ipa to view the adapter connection thus acquire the user and password to my mysql database.
A hacker decompiling your .apk or .ipa file will not find the database username/password there, for the simple reason that the adapter is not compiled "together with the app" and is not part of any artifacts that you install in a device.
An adapter is a server-side entity, not client-side.
The adapter is an object stored in the memory of the running application server.
Adapters are Server side code andare not part of the apk or ipa files.
You can check/confirm this information in Worklight documentation. The details about adapters, under "Developing the server side of a Worklight Application" are at:
http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_overview_of_ibm_worklight_adap.html
You can also check the Server Side Development of MobileFirst Platform Getting Started Modules
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/server-side-development/
(MobileFirst Platform is the new name of Worklight)
In worklight, you usually have the application (apk/ipa) communicating with a server side component (the adapters) running in a worklight server. The adapters are used to communicate with backend systems (like a mysql server). There are a few different types of adapters to communicate with different types of backends (like sql, http and SAP)
Please, let us know what documentation/guide caused you the understanding that adapters are part of the client apk/ipa. If that is really stated in any documentation, it is wrong and must be corrected.
Edit:
To connect to a MySQL DB (no matter if it is a standalone MySQL or in XAMP, LAMP or whatever package) you can follow this geting started tutorial
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/server-side-development/sql-adapter-communicating-sql-database/
Also note that, if you are using MobileFirst Studio (previously Worklight Studio) downloaded for free from Developer Works you have a developer version of the WOrklight Server running inside Studio so that you can create and deploy adapters and use it during development as your server. But when you go to production you are required to purchase licenses of Worklight because you don't have the worklight server available for free.
So if you have Studio, you have the server available but only for development purposes.

Publishing ASP.NET MVC 4 Web Application with Mysql Database

I have successfully created a ASP.NET MVC 4 Web application and now I want to deploy it on a test environment. The target server is not an Azure server, but it is a Windows Server 2008 R2 Server with IIS installed in it.
Now I have published my solution using Visual Studio 2013 Professional, everything works fine excepts the Database. It's a Mysql Database that works perfectly with Entity Framework 5 (I have added the Mysql provider, mysql.data.entity.dll , mysql.data.dll on my web project and all the configuration to make it run locally). Once I publish the project, it is deployed on IIS but it doesn't retrieve data from my Mysql Database. I want to notice also that in the Publish wizard, although I specified the connection string, it says that
there is no Database detected
It should display the name of my context instead of that. Would you please help me know why the publishing wizard doesn't recognize my Mysql Database? thank you for your help !
I was able to use Asp.net MVC with MySql using Entity Framework code first, like the one explained here http://www.asp.net/identity/overview/getting-started/aspnet-identity-using-mysql-storage-with-an-entityframework-mysql-provider ... Here a couple the things I notice:
The generated migration contains the schema dbo. that won't work on MySql so I went to the migration file and remove all schema references. (there are better solutions, like configuration/setup wise)
The unique key length problem, such as UserName (defined in the asp.net Identity) has a maximum length of 256 and that is over the limitations of mysql unique field, so I changed the length to 128. that solved this error
Specified key was too long; max key length is 767 bytes
I did have some troubles using the publishing wizard, since didn't show me any of my MySql Drivers to test my connection to my db, so I just change the Connection string in the config file and apply my migration changes to the new/testing DB from the Package Manager Console > Update-Database (this could be your temporary solution until you find a automatized solution)

Unable to find the requested .Net Framework Data Provider, Webmatrix ,Wordpress

I installed WebMatrix on my Windows 8.1 computer. Now I'm trying to install wordpress from within WebMatrix. When I give it user and db info and click next.
I get this error:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
The MySQL Connector for .Net is required in order to perform this operation. Object of type 'dbMySql' and path 'server=localhost;uid=root' cannot be created. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_EXCEPTION_WHILE_CREATING_OBJECT.

Troubleshooting MySQL with Entity Framework

When I connect to MySQL using the workbench it works fine.
When I connect to MySQL using Java it works fine.
When I connect to MySQL using the Entity Framework designer (e.g. Update Models from Database) it works fine.
But when I run the project I get "No connection could be made because the target machine actively refused it".
The Entity Framework designer is using the same connection string as the application. What else could be the problem?
EDIT:
When I connect to MySQL using Entity Framework in a console application it works fine.
When I connect to MySQL using Entity Framework in a console application in debug mode it works fine.
When I connect to MySQL using Entity Framework in a unit test project it works fine.
When I connect to MySQL using Entity Framework in a unit test project in debug mode it doesn't work.
Is your debug mode and release mode configurations the same? IE is one running in x86 and the other in x64?