How to get ELMAH to log to MySQL? - mysql

I've been looking around with this question and there are barely any answers.
Previously, we have been using ELMAH to log to a table in Microsoft SQL Server, however we are changing the backend to use MySQL instead(MariaDB specifically).
So all was fine, the errors had been logging to SQL Server. I have installed the ELMAH MySql package and changed the connection strings to use the new MySQL table. However, when an error is thrown, no error gets logged. I'm confused to why this is happening.
It really doesn't help that there are virtually any documentation on this. For example, are you supposed to just install ELMAH.MySQL on its own? Or does it need to go with my previous ELMAH configurations?
ELMAH webconfig:
<connectionStrings>
<!-- TODO: Replace the ****'s with the correct entries -->
<add name="elmah-mysql" connectionString="server=web01;UserId=root;Password=Tr#nsf0rmers;database=elmah; CharSet=utf8;Persist Security Info=True" />
</connectionStrings>
<elmah>
<security allowRemoteAccess="0" />
<errorLog type="Elmah.MySqlErrorLog, Elmah.MySql" connectionStringName="elmah-mysql" />
</elmah>
<appSettings>
<add key="elmah.mvc.disableHandler" value="false" />
<add key="elmah.mvc.disableHandleErrorFilter" value="true" />
<add key="elmah.mvc.requiresAuthentication" value="false" />
<add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
<add key="elmah.mvc.allowedRoles" value="*" />
<add key="elmah.mvc.allowedUsers" value="*" />
<add key="elmah.mvc.route" value="elmah" />
<add key="elmah.mvc.UserAuthCaseSensitive" value="true" />
</appSettings>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<modules>
<remove name="FormsAuthentication" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
</modules>
Exception handler:
public class ElmahHandledErrorLoggerFilter : IExceptionFilter {
public void OnException(ExceptionContext context) {
// Log only handled exceptions, because all other will be caught by ELMAH anyway.
if (context.ExceptionHandled)
ErrorSignal.FromCurrentContext().Raise(context.Exception);
}
}
It hits this code.
Seriously, what gives?

Right well I managed to get it to work by doing the following. I uninstalled all of my ELMAH references. Reinstalled them, installed the MySQL ELMAH package and then changed the connection strings and it worked. Just like that.
Follow this guide: https://dillieodigital.wordpress.com/2011/03/30/elmah-a-quick-start-tutorial-and-guide/
And convert to MySQL where he uses SQLite instead.

Related

Using MySQL the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is either not registered in the machine or application config file

I am working on creating Rest API using the visual studio in asp.net MVC. The database I am using is MySQL. I am getting below error while running the API.
Severity Code Description Project File Line Suppression State
Error Error 175: 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. DataAccess D:\Work\DOT NET API\RestWithMySQL\DataAccess\ProductsModel.edmx 7
I have two projects in my single solution. Data Access project in which I have added the model and RestWithMySQL project in which I have added my control and the model is added as a reference in it.
When I click on the error I am redirected to the following section
<edmx:StorageModels>
<Schema Namespace="ProductsModel.Store" Provider="MySql.Data.MySqlClient" ProviderManifestToken="5.5" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
<EntityType Name="product">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="Name" Type="varchar" MaxLength="100" />
<Property Name="Price" Type="int" />
<Property Name="Category" Type="varchar" MaxLength="100" />
</EntityType>
<EntityContainer Name="ProductsModelStoreContainer">
<EntitySet Name="product" EntityType="Self.product" Schema="accurate_dev" store:Type="Tables" />
</EntityContainer>
</Schema>
</edmx:StorageModels>
My config file is below
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-RestWithMySQL-20170911031521.mdf;Initial Catalog=aspnet-RestWithMySQL-20170911031521;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="ProductEntities" connectionString="metadata=res://*/ProductsModel.csdl|res://*/ProductsModel.ssdl|res://*/ProductsModel.msl;provider=MySql.Data.MySqlClient;provider connection string=" Server=localhost; Uid=root; Database=accurate_dev; Port=3306;SslMode=Preferred" providerName="MySql.Data.MySqlClient" />
<!--<remove name="LocalMySqlServer" /><add name="ProductEntities" connectionString="metadata=res://*/ProductsModel.csdl|res://*/ProductsModel.ssdl|res://*/ProductsModel.msl;provider=MySql.Data.MySqlClient;provider connection string=" Server=localhost;Uid=root;Pwd=;Database=accurate_dev;" providerName="MySql.Data.MySqlClient" />-->
I have searched for every solution related to it but still can't able to get the desired result.
Any help would be highly appreciated.
Assuming you've referenced MySql.Data with NuGet, make sure you have a system.data section in your web/app.config to override the factory for your version. The version should match that of your nuget reference.
e.g.
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

User created with ASP.Net Web Site Administration Tool is not stored in the Membership database

I created a new MVC 4 Web Application with Visual Studio Express 2010. A membership database was automatically created on a local SQL Server express database 2008.
Database server: {local computer name}\SQLEXPRESS
Database name: aspnet-{project name}-{yyyymmddhhmmss}
When I ran the web application, I managed successfully to add a new user and the user was stored in the membership database. This means the web app was connected with membership database.
However, when I brought up the ASP.Net Web Site Administration Tool, it showed 0 user. Any new users that I created on the Admin Tool were not stored in the membership database.
Could anyone help with any idea about it? Thanks
By the way, the connection string in the web.config looks like:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-MvcApplication-20140505092727;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

Cannot connect to SQL server AppHarbor

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Is the above relevant? I just have it in there in order not to screw things further.
But below is what I'm interested in, it is a connection string of my local sql server
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=TestDB;User ID=lews;Password='therin'" providerName="System.Data.SqlClient" />
"When you create a database on Sequelizer you can specify a connection string alias. This is done on the Sequelizer add-on page (follow the "Go to ..." link on the application overview). If you set this name as the name of your connection string in your configuration file, we'll automatically replace it with your Sequelizer connection string when your code is deployed."
That's a snippet from Appharbor's documentation. So I assume that Data Source, Initial Catalog, User ID and password is automatically replaced with the correct values by AppHarbor. But it can't connect for some reason.
Below is another string I am using with MySQL this time, again I assume that AppHarbor should automagically inject the right values, but the error it gives is:
"PeopleEntities cannot be found in the application configuration file"
What is going on?
<add name="PeopleEntities" connectionString="metadata=res://*/Context.People.csdl|res://*/Context.People.ssdl|res://*/Context.People.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;database=people"" providerName="System.Data.EntityClient" />
</connectionStrings>
Btw, the names "PeopleEntities" and "ApplicationServices" are used as aliases on AppHarbor.
And I have no idea how to use the code given in the documentation, databases is just not my thing.. how do I use both local and remote conn strings? Where in the code do I build the string and inject it? Do I have to do it whenever I create a DBContext instance? Etc..
Any ideas will be great, thanks!
EDIT:
Btw, if I hard code the connection strings, in the app.config and use a wcftestclient, it works, it queries the database.. but this isn't a good idea, apparently the connection strings can change without warning.
Anyway if I deploy it with the strings hardcoded and connect to the database with my site.. it doesn't query the SQL server.. really confused :(
http://support.appharbor.com/discussions/problems/2687-solved-mysql-provider-with-entity-framework-problem
For Entity Framework:
This piece of markup is unbelievable important:
<system.data>
<DbProviderFactories>
<clear />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Oh make sure the MySQL connector assemblies are local. And it should be in your web.config file as well, to be extra sure place it in your WCF's App.config. Use the same addon alias in your connection string.
For SQL Server addon:
You need this markup in the web.config:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
<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="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
</system.web>
And you should be good to go..

Cannot Connect to ASPNETDB in Production server using SQL Server 2008 R2 Standard Edition

I am a newbie in ASP.net and just following Tutorials. This Particular Problem has been Giving me a Real Headache, I have developed a website in VS 2010 , used the ASPNETDB SQL server database provided by Asp.Net Login Controls for creating users and roles. Also added Some tables, After i Was Done Used the " publish to Provider " feature to generate the Script (ASPNETDB.MDF.sql) . I Used this Script to Generate the Database and Tables -Sql Server 2008 R2 management Studio, and Modified the web.config Like This-
<!--Connection String-->
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Server=AkumJamir-PC\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="con" connectionString="Server=AkumJamir-PC\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True"/>
<add name="ConnectionString" connectionString="Server=AkumJamir-PC\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<roleManager enabled="true">
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add connectionStringName="ConnectionString" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider,System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove name="AspNetWindowsTokenProvider"/>
</providers>
</roleManager>
<membership>
<providers>
<remove name="AspNetMembershipProvider"/>
<add connectionStringName="ConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphaNumericCharacters="1" passwordAttemptWindow="5" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider,System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
<webParts>
<personalization defaultProvider="AspNetSqlPersonalizationProvider">
<providers>
<remove name="AspNetSqlPersonalizationProvider"/>
<add name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.Webparts.SqlPersonalizationProvider"
connectionStringname="ConnectionString" applicationName="/"/>
</providers>
</personalization>
</webParts>
Now The Problem is That Works On my Development Machine But on our Staging Server, It Doesnt connect to the Database whenever i try browse to Some Pages where i have some data to be displayed from the Database Neither Does the Login Page Work.The connectionString Looks Like This in the Server:
<!--Connection String-->
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Driver={SQL Native Client};Server=WIN-K16NMM4128C;Initial Catalog=ASPNETDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="con" connectionString="Server=WIN-K16NMM4128C;Initial Catalog=ASPNETDB;Integrated Security=True"/>
<add name="ConnectionString" connectionString="Data Source=WIN-K16NMM4128C\SqlServer2008;Initial Catalog=ASPNETDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
I Am Eating My braings Away, I've Gone through the Topics Covered Already,,,, Thanks For any Advise...
I was facing the same issue. I've just enabled ASP/Authentication in IIS manager and I've set Basic Authentication=true. It is working now.
You are using integrated security in your connection strings. Configure it to use sql authentication. Something like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

ASP.NET MVC 2 - Trying to configure role/user management via ASP.NET Configuration Tool

First, my development environment: Win7 laptop with Visual Studio Professional 2010. IIS is NOT installed.
I'm trying to turn on and set up some roles for user management via the ASP.NET Configuration Tool, as demonstrated in the MVCMusicStore tutorial. When I click on the 'Security' tab, I get the following error:
"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Could not load type 'HandiGamer.MvcApplication'."
When I click on the 'button below', it tells me I'm using AspNetSqlProvider as my provider. When I try to test it, it tells me:
"Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider."
Here's the thing:
The MVCMusicStore demo's role/user management works when I run it through the debugger. I can add myself as a customer, and add/remove items from my cart. Despite this, when I attempt to use the Configuration Tool with it, I get the same errors.
I actually have run aspnet_regsql on my copy of SQL Server 2008 Express. It created the necessary tables for user management. Still didn't fix my problem.
I'm just wondering if I'm missing something obvious, as the tutorial essentially said "Click two buttons and you're all set." It literally said nothing about setting up the db for this.
I'm just stumped at this point. Role/user management works (the MVCMusicStore proves that it does), but the configuration tool won't let me turn it on, set it up, or otherwise edit how it works. It's becoming very frustrating. Any help would be greatly appreciated.
EDIT: My web.config is as follows-
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="HandiGamer" connectionString="data source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|handigamer.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</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="HandiGamer" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="HandiGamer" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="HandiGamer" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="HandiGamer" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Found the solution. Had to compile/build my solution before the config tool would 'see' the db security stuff.