migration from SQL Server to MySQL _ ASP.NET 4 and EnterpriseLibrary 5.0

Dec 27, 2011 at 9:20 PM
I am trying to connect from a SQL Server connection string (commented out in the web.config) to a mysql one.
I am getting the following error :
The type Database cannot be constructed...

My web.config is as follows :

<!--New config file by IB -->
<configuration>

<!--START : ADDED FOR ELMAH -->
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<section name="membase" type="Membase.Configuration.MembaseClientSection, Membase" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>


<membase>
<!--
Bucket is optional and can be specified in the constructor, so you
can use the same configuration to connect to different buckets in the cluster.

You must provide userName and password if the server is "secured" (membase is secured by default).

- bucketPassword (optional) : set the password of your bucket. Optional for membase 1.6+ where the client canfind this out automatically.
- retryCount (optional, default 0): the number of times to reconnect to a pool url before marking it as dead. (useful for ec2/amazon where the load balancer closes our connection to the pool)
- retryTimeout (optional, default 2secs): the time to wait between two retry attempts
-->
<servers bucket="enyim" bucketPassword="pwd" userName="Administrator" password="pwd" retryCount="2" retryTimeout="00:00:02">
<!--
Provide at least 2-3 urls from your cluster.
Usually you only need to change the host, except when connecting to older versions.
Membase uses port 8091, while the NorthScale Memcached Server (1.0.3) uses 8080
-->
<add uri="http://50.30.32.4:8091/pools/default" />
<add uri="http://50.30.32.23:3306/pools/default" />
</servers>
<!-- the client waits deadTmimeout time to reconnect to the pool when all the specified urls are down -->
<socketPool connectionTimeout="00:00:10" deadTimeout="00:00:10" />
</membase>
<elmah>
<errorMail from="dan@cloudmobmedia.com" to="suvendu.banik@digitalavenues.com;mala.gupta@digitalavenues.com;shirsendu.nayak@digitalavenues.com" subject="Error Log"
smtpServer="smtp.gmail.com" userName="dan@cloudmobmedia.com" password="pwd" useSsl="true" async="true"/>
</elmah>
<!--END : ADDED FOR ELMAH -->




<connectionStrings>
<!--<add name="CloudMobDSN" connectionString="Data Source=50.30.32.23\sqlexpressr2;Initial Catalog=cloudmob;Persist Security Info=True;User ID=cloudmob;Password=pwd" providerName="System.Data.SqlClient" /> -->
<add name="CloudMobDSN" providerName="dotConnect for MySQL" connectionString="host=50.30.32.23;port=3306;database=cloudmob_dbo;User id=root;Password=pwd" />
</connectionStrings>

<dataConfiguration defaultDatabase="CloudMobDSN">
<providerMappings>
<add databaseType="Devart.Data.MySql.EnterpriseLibrary.MySqlDatabase,Devart.Data.MySql.EnterpriseLibrary" name="dotConnect for MySQL" />
</providerMappings>
</dataConfiguration>

<system.web>
<customErrors mode="Off" />
<httpRuntime requestValidationMode="2.0"/>
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>

<compilation debug="true" >
<assemblies>
<add assembly="MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</assemblies>
</compilation>

<authentication mode="Forms">
<forms name="CMob" loginUrl="~/Login.aspx" timeout="2880" cookieless="UseDeviceProfile" path="/" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages enableViewStateMac="false" enableSessionState="true">
<controls>
<add src="~/Controls/UpdateProgressBar.ascx" tagName="ProgressBar" tagPrefix="uc" />
<add namespace="DAL.WebControls.Grid" tagPrefix="ctrl" />
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="cc1" />
</controls>
</pages>

</system.web>



<appSettings>
<!--Start of Mail Settings-->
<!--For 50.30.32.166 -->
<!--<add key="reCaptchaPublicKey" value="6Lf9g8QSAAAAAJuHSZkTJBa-zsfL9pvXKvDu5FtW"/>
<add key="reCaptchaPrivateKey" value="6Lf9g8QSAAAAABQN891kjX1cucMeHWo9Q-wEErCP"/>-->

<!--For y.digitalavenues.com -->
<add key="reCaptchaPublicKey" value="6LdFjMQSAAAAAAd9MXgikq_RY7EAEQPMDMqvesOu" />
<add key="reCaptchaPrivateKey" value="6LdFjMQSAAAAACVwkTShDOK6v_v_QL6d_0Amcryu" />

<!--For Local host -->
<!--<add key="reCaptchaPublicKey" value="6Lfmi8QSAAAAALiQ8g4RLvSEP4j-rtLtCE9n7i0b"/>
<add key="reCaptchaPrivateKey" value="6Lfmi8QSAAAAAAYcnj0Oj724C6t96Jk3ZiGs5YAp"/>-->

<add key="MailServer" value="smtp.gmail.com"/>
<add key="UID" value="dan@cloudmobmedia.com"/>
<add key="PWD" value="pwd"/>
<add key="MailFrom" value="dan@cloudmobmedia.com"/>
<add key="MailCC" value="mala.gupta@digitalavenues.com"/>
<!--End of Mail Settings-->
<add key="FooterText" value="&amp;copy 2000 - 2012 CloudMob Media. All Rights Reserved." />
<add key="EmailTemplate" value="~/EmailBodyContent/Template1.html" />

<!--Help Default Images-->
<add key="HelpTextImage" value="hintTick.png" />
<add key="TitleArrowImage" value="hintPointer.png" />
<!--For Schedular-->
<add key="AdminMailTo" value="dan@cloudmobmedia.com" />
<add key="ValidIPForScheduler" value="50.30.32.4,59.162.178.58" />
<add key="ChartImageHandler" value="Storage=file; Timeout=180; Url=~/TempImages/; deleteAfterServicing=false" />
<add key="TempImageFolder" value="~/TempImages/"/>
<!-- Specifies the days the creatives will be served as random before performance wise selection takes place-->
<add key="ServeCreativeRandomlyDays" value="7" />
<!--For Campaign mail-->
<add key="AdminMail" value="mala.gupta@digitalavenues.com"/>
<add key="IsAdvertiserAdmin" value="true"/>
<add key="IsAgencyAdmin" value="true"/>
<!--For Contact Template-->
<add key="ContactMail" value="help@cloudmobmedia.com"/>
<!--For Error Log-->
<add key="FilePath" value="~/ErrorLog/MessageLog.txt"/>
<!--Password for Membase-->
<add key="MembasePassword" value="pwd" />
<!--For Error Log-->
<add key="FilePath" value="~/ErrorLog/MessageLog.txt"/>
</appSettings>

<system.webServer>
<defaultDocument>
<files>
<add value="login.aspx" />
</files>
</defaultDocument>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true" />
</system.webServer>

</configuration>

______
I have downloaded the dotConnect for mySql and copied the dlls in my bin dir.

Can you help ?
Coordinator
Dec 28, 2011 at 2:55 AM
Edited Dec 28, 2011 at 2:59 AM

Hi iunabilly,

From what I can gather from your web.config, you are missing a few things that may be causing your problem. For example, you connectionstring has an incorrect providerName. If you are using mysql, it should be set as providerName="MySql.Data.MySqlClient". Also, NearForums uses the DbProviderFactory class to be database-agnostic, so you need to set the correct implementation of that class in the DbProviderFactories section of the web.config inside the configuration section:

<configuration>
........
<system.data>
		<DbProviderFactories>
			<remove invariant="MySql.Data.MySqlClient"/>
			<add invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/>
		</DbProviderFactories>
	</system.data>
.........
</configuration>

As a side note, NearForums does not use Enterprise Library, so you don't need it, unless, of course, you are using it for some other application. Also you should consider removing any sensitive information on that config that you posted.

Please let us know if the above suggestion works for you and If we can help you with something else.

Kind Regards,

Jason

Dec 28, 2011 at 1:47 PM
Edited Dec 28, 2011 at 4:30 PM

Thanks Jason. I have added the DBProvider block.

I had to change the providerMappings block as follows :

 

<dataConfiguration defaultDatabase="CloudMobDSN">
    <providerMappings>
 <add name="MySql.Data.MySqlClient" databaseType="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=6.4.4.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d"/>

 

Now i have another error :

 

 

The type MySqlClientFactory does not contain the ConfigurationElementTypeAttribute.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type MySqlClientFactory does not contain the ConfigurationElementTypeAttribute.

 

 

 

Did i make a new mistake ?

Dec 28, 2011 at 4:30 PM

Also now i took out the dataConfiguration section and i am getting this error :

 

Parameter discovery is not supported for connections using GenericDatabase. You must specify the parameters explicitly, or configure the connection to use a type deriving from Database that supports parameter discovery.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Parameter discovery is not supported for connections using GenericDatabase. You must specify the parameters explicitly, or configure the connection to use a type deriving from Database that supports parameter discovery.

Coordinator
Dec 29, 2011 at 10:54 PM

Hi,

It is very difficult to grant support to your solution because we can not reproduce your environment, ... Your application is very different from the provided in the Nearforums release. 

Sorry,

Kind Regards,

Jorge