I previously wrote a post about configuring MySQL for use with a Microsoft MVC application. I noticed after publishing that my application could not connect to the database and returned the following exception:
System.ArgumentException: The ADO.NET provider with invariant name ‘MySql.Data.MySqlClient’ is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. —> System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
In order to solve this I had to do two things:
In the Solution Explore under ‘References’ set Copy Local to true for the MySql.data reference
Add the database provider configuration to your Web.config as seen below, with your particular version
<system.data><DbProviderFactories><addname="MySQL Data Provider"invariant="MySql.Data.MySqlClient"description=".Net Framework Data Provider for MySQL"type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=188.8.131.52, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/></DbProviderFactories></system.data>
<add name="MySQL Data Provider"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=184.108.40.206, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
The reason for #2 is that I am trying to run my code on a machine where the provider is not installed, so I have to specify the provider in my configuration file and then installation adds it to the machine.config registering the provider on the remote server.
The web hosting provider I am using is GoDaddy and I chose Windows hosting since some of my ideas include developing web applications using Microsoft technologies. The following explains how I set up my first web project I am in the process of developing, which was my tracker application.
The first step is to get the web deploy publishing settings for the location you wish to host your web project. In my case I want to host it on a subdomain (which I have already created), but the steps are the same if it is your root domain. You navigate to the subdomain section of where you would like to host your app in GoDaddy’s ‘Websites & Domains’ section. You then click the ‘Web Deploy Publishing Settings’ link to start the download of your settings file (seen in Figure 1 below).
The downloaded file will contain a .publishsettings extension with the contents of the file similar to:
<?xmlversion="1.0"?><publishData><publishProfileprofileName="tracker.dwcryan.com - Web Deploy"publishMethod="MSDeploy"publishUrl="tracker.dwcryan.com"msdeploySite="tracker.dwcryan.com"userName="dwcryan"destinationAppUrl="http://tracker.dwcryan.com"controlPanelLink="https://p3nwvpweb100.shr.prod.phx3.secureserver.net:8443"/></publishData>
Once you have the settings file you can configure your actual project. With your web project opened in Visual Studio you right click on the project in the Solution Explorer and select Publish.. (or something similar depending on project type) as in Figure 2.
This will present you with the window in Figure 3, where you will select the Import option by left clicking. In the displayed dialog ‘Import Publish Settings’, also displayed in Figure 3, you will browse to your publish settings file, select it, and then click Open; thus, displaying the path to your file in the ‘Import Publish Settings’ dialog as in Figure 4, and then click OK.
Once the settings have loaded enter the password for your account and click Test Connection. If everything is OK you will see a check mark next to the test connection button as in Figure 5.
Clicking Next will then take you to the ‘Settings’ tab. I did not change anything here as I did not see the need for any file publishing options and I do not want the publish to modify my database. I may need to update my publish settings and insert a connection string for my database once I have that configured within my application and will update this post with any such changes. Clicking Next again brings me to the ‘Preview’ tab as in Figure 6.
Clicking ‘Start Preview’ in the middle of the screenshot above (Figure 6) will provide a list of the files being uploaded and the action being performed (i.e. update for files being modified and add for new files being pushed to the destination) as in Figure 7.
Lastly you click Publish to finish off the process which will publish your application to its destination. The output of the file will look similar to that of Figure 8 (I cropped out the middle section as to highlight the start and end sections as well as displaying some of the adds and updates. The web application (at the URL provided) will then open up in your default web browser.
If their are issues with the settings in your application when running on the remote server an error page will be displayed with some information as to what you have to do. At this point it becomes a matter of experimenting. In my case I got a security exception stating “The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file”.
I was able to solve this by adding the following line to my web.config file between the system.web tags and publishing again:
<trust level="Full" />
Through further investigative work I determined a second option is changing the configuration on your hosting provider, if they allow it. In my case that involved selecting the option ASP.NET Settings in the same view as Figure 1 above, which in my case was at the bottom of the 3rd column (from the left). Once in there you set the CAS trust level to Full, Figure 8 below, and while here make sure that the Default webpage language is correct for your application.
That appears to be it for now and will have to see what happens once my web application contains a database and actions are being taken if any further modifications to the publishing settings need to be added or modified.