Recently I wanted to host my ASP.Net MVC application which runs with MySql in the backend. Since I am new to MySQL and Asp.net, it was a little difficult for me to search for the right things for hosting a web application with database.
After some googling with no help decided to write my very first technical blog explaining the steps so that someone will find this helpful. :)
I am deliberately not giving links, so that you can be better googlers.. :) Take hints from the blog and search for the downloads.Thanks to Edwin for helping me in MySql. This is what I did.
Asp.Net

-Copy the necessary files and folders into the wwwroot folder in the hosting machine.
-In IIS -> convert folder to application -> right click -> convert application.

Run it. -> Boom you will obviously get an error. 
.Net data provider may not be installed. 
- To work around this you can do 2 things,    -Either install the connector in the host machine or    -Copy the connector dll to the application path. 

-Check this in the machine.config file. If this is not there add it.
    - There has to be a entry under <system.data> <DbProviderFactories>        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" /></DbProviderFactories>
  </system.data> 

-In the application web.config file give the connectionstring with the correct credentials.
<add name="entities" connectionString="provider=MySql.Data.MySqlClient;provider connection string=&quot;server=mysqlhostname;User Id=root;database=databasename&quot;" providerName="System.Data.EntityClient"/>

Now, run it. You will get an error saying that your host machine is not allowed to access the database.

The reason is, you have not given grant permission for the databases. So not go to mysql and grant the permission for the host machine.

MySQL
-use root to login to mySql
-update the db table in 'mysql' database. "db" is a table in "mysql" database. This sets the permissions on who can access the tables.
   -Insert the values in db table.
insert into db values ('host machine name','database name','used name','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y'); 
   - 'y' - are the privilages you give for the host. Put a 'desc' on the db table to list all the columns.

Now try running the application. Hurrah..!! It works. :)

Thats all. Hope someone finds this useful.

-Jasper




 


Comments




Leave a Reply