Unable to find the requested .Net Framework Data Provider. - asp.net-mvc-4

I've seen several posts about this, but none of the answers seem to work.
I'm trying to set up simplemembership and I keep getting this error when WebSecurity.InitializeDatabaseConnection(...) is called
Here is the ConnectionsStrings entry:
<add name="JBarterMain" connectionString="Data Source=winsrv01;Initial Catalog=ProvausioJBarter;Persist Security Info=True;User ID=xxx;Password=xxx" providerName="System.Data.SqlClient"/>
I tried adding the following to my machine config in the .net 4.0 x64 folder:
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
I'm getting absolutely nowhere. This seems incredibly odd to me that this wouldn't work out of the box. I had another project a few months ago (broken currently so I can't verify that it still works) that was working just fine and I didn't have to do any additional configuration.
Any ideas?

I wrote a tutorial on how to set up simple membership Here. Also I prefer to ditch the filters and initialize it directly on application start

Related

WCF Service Library app.config file

It is my understanding that when you deploy a service library the app.config not required as the host does not acquire nor use this file and instead uses its own app.config file! Hence why you have to put the database connection string in the hosts config file.
However, what I don't understand is how do you provide configurations within service library?! I realise that question may not be clear so let me provide an example...
In my service library I make use of the entity framework - upon adding the ado.net (via the wizard) the following was added to the app.config file:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
So, I am not going to claim to know exactly how purposeful these tags/settings are, but as a quick test I removed them and ran the host and the service worked the same as ever... so this got me thinking! Firstly, I imagine removing these tags didn't affect the service as there are default settings in place which will have been implemented by the entity framework?! and secondly what IF I am required to add specific entity framework configurations at a later date? How would I do that when the config file within the service library is redundant?
Of course this may not be deemed the best example of the "problem" I am trying to portray, but I hope you can understand my confusion and I would greatly appreciate an explanation regarding this scenario!

MVC4 - Membership - SQL Server Compact 4.0 - Exception: Unable to find the requested .Net Framework Data Provider

The InitializeDatabaseConnection Method documentation says we can use the MVC 4 "Internet" template's generated membership functionality with SQLCE (SQL Server Compact 4.0 Local Database).
I've used this template many times before and have never had a problem when I didn't fiddle with anything and simply used the localDb (the default) that is generated by the Entity Framework the first time we register a user.
My requirement is to get the membership tables that are by default generated into 2012 localDb database instead to generate into a SQLCE database. However, I'm getting the following:
Exception: Unable to find the requested .Net Framework Data Provider. It may not be installed.
To do this we simply:
Open Visual Studio (express works fine).
Generate a new MVC4 --> Internet (with account) project.
Add a SQLCE database to the ~/App_Data/ folder (right-click the folder and select Add --> SQL Server Compact 4.0 Local Database).
Add table then a record to the table.
Right-click the Models folder and select Add --> ADO.NET Entity Data Model
Open the (root) web.config and copy the name of the 'connectionstring'(<add name="ceEntities")
Locate the following line of code in the ~/Filters/InitializeSimpleMembershipAttribute class: WebSecurity.InitializeDatabaseConnection("ceEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
F5 to compile/run/debug the project
Once the home/index page loads click the "Register" link in the upper right hand corner
Enter a username and password to register and click 'Ok.'
Up to this point the code compiles and runs fine however when the following line of code is run in the ~/Filters/InitializeSimpleMembershipAttribute class:
WebSecurity.InitializeDatabaseConnection("ceEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
This exception is caught:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
Which is apparently fixed when we add this code to the web.config:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
And when we run it again the following exception is caught:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
Thank you to Scott Hanselman and whoever made him aware of the Membership Provider with SQLCE protocol as in his Introducing System.Web.Providers - ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQL Compact and SQL Azure blog post Scott outlines the steps to implement the ASP.NET Universal Providers. This helped me as he outlined the proper connection string outline for SQLCE:
<connectionstrings>
<add name="Sql_CE"
connectionstring="Data Source=|DataDirectory|\MyWebSite.sdf;"
providername="System.Data.SqlServerCe.4.0">
</add>
</connectionstrings>
So I updated my connectionstring to:
<connectionstrings>
<add name="defaultconnection"
connectionstring="Data Source=|DataDirectory|\ce.sdf;"
providername="System.Data.SqlServerCe.4.0">
</add>
</connectionstrings>
Then updated connectionStringName the ~/Filters/InitializeSimpleMembershipAttribute class back to:
WebSecurity.InitializeDatabaseConnection("defaultconnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
The application compiled without an error or exception so I ran the application then Registered a user and in that process the applicable SimpleMembership tables were generated into my "ce.sdf" (SQL Server Compact 4.0 Local Database).
I am now able to utilize the SimpleMembership default's at their fullest!
p.s., For brevity I'm going to now edit my initial post/question to omit the stacktraces, leaving only the exceptions.
Random suggestion but it may need to be added.as a namespace to the web.config file or as a package in the packages file, I could be wrong

Enable WPFApplication access to existing WCF RIA Services

I have a big (too big for me, about 50k line) Silverlight application, written by an ex-colleague. It is written really (really really) badly so I'm not going to change/touch almost nothing.
I'd like to easily enable access to his WCF RIA Services from a WFC command line app. There's almost 30 domain service class in the web part of SL app.
I installed the SL and WCF-RIA toolkits.
I've added those lines in the web.config but the compiler doesn't recognize the <domainServices>.
<domainServices>
<endpoints>
<add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</endpoints>
</domainServices>
From the new command line app I can't see any services in my solution.
Any Idea of what I'm missing? Thanks
Maybe the problem rely on the way you try to add the service reference: auto discover don't work and you don't have an .svc file. You should use something like http://[hostname]/[namespacename]-[classname].svc but I recommend to have a look at these articles: http://blogs.msdn.com/b/saurabh/archive/2009/11/23/understanding-the-wcf-in-wcf-ria-services.aspx and
http://blogs.msdn.com/b/brada/archive/2009/11/22/ria-services-a-domainservice-is-a-wcf-service-add-service-reference.aspx
that give a detailed insghts

Trying to find out why my WCF service is not working

Over a year ago I had been working on a WCF service, which I wrote using VS 2008. It runs under a Windows service, which I also wrote. It’s been running there ever since. And unfortunately, other projects/priorities have come up, preventing me from continuing with that project, until now.
Now I’m trying to get back to it. However, this go around I’m trying to find out if I can use VS 2010 and .NET 4, instead of .NET 3.5. I’ve brought up the command prompt, to run SvcUtil, to get the wsdl information, which I’ll put into the config file for the new WPF app I’m trying to get started writing. Only thing is, I keep getting an error, saying that I can’t reach the server, etc.
So, I copied the .exe.config file from the server to my machine, where I could edit it with SvcConfigEditor. I’ve made those changes, put it back onto the server, and got an error while trying to run SvcUtil, but worse than that I didn’t see the .svclog files I expected to see. So I got into the server’s Services app. I found the Windows service I wrote a year ago; saw that it was running, and stopped and started it again.
Now I’ve got a different problem. My Windows service starts, but then stops immediately. I get this message saying that the service had started and then stopped, and saying that sometimes that happens with different sorts of services, like Performance Logs and Alerts services. I’ve checked the event log on the server, and then only thing there related to this Windows service is that it entered the start state and then entered the stopped state.
Ah, after attempting to start it 4 times, it finally gave me an error in the event log! (Why didn’t it do that in the first place? And who says that trying to do the same thing over and over again, and expecting different results is a sign of insanity, when clearly the first 3 times it didn’t register anything in the event log, but on the 4th try it did.)
Here’s the error:
Event Type: Error
Event Source: Service1
Event Category: None
Event ID: 0
Date: 5/4/2011
Time: 10:14:46 AM
User: N/A
Computer: HELIOS
Description:
Service cannot be started. System.TypeInitializationException:
The type initializer for 'System.ServiceModel.DiagnosticUtility'
threw an exception. --->System.Configuration.ConfigurationErrorsException: Couldn't find type
for class System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089.
at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType,
String initializeData)
and here’s the new section of code put into the .config file by SvcConfigEditor:
<sharedListeners>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
This question was answered in the comments but there is a gotcha that I've seen in Visual Studio 2010 that could result in a similar situation.
Even if the target framework is set to version 3.x for a WCF project, using the 2010 SvcConfigEditor will automatically insert "System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0..." although it should be inserting "System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0..." This will bite you when deploying the altered web.config to an IIS hosted service where the AppPool is not configured to use the .NET 4.0 framework. The fix is simply edit the web.config back to "Version=2.0.0.0".

SecurityException after adding ELMAH to WCF project

I'm having a problem with a WCF (.Net 3.5) site using ELMAH on IIS 7.5. This is the exception message:
System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
To verify that it was the combination of WCF and ELMAH on IIS7.5, I created a new WCF Service project in VS2008 and a new Application under the IIS 7.5 site. I published it and made sure it was okay. Then I added the ELMAH DLL. Still okay. Then added the ELMAH configSection references to Web.config. Still okay. Then I added the ELMAH stuff to httpHandlers and httpModules in system.web (yeah, I know this is not for 7.5). Still okay. Then I added this to handlers and modules in system.webServer:
<handlers>
:
<add name="Elmah" verb="POST,GET,HEAD"
path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
<modules>
:
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
And then I got the security exception. I've made no other config changes.
Everything works using the VS dev webserver. The development machine is 2008 R2 x64 with VS 2008 SP1 installed. The WCF service is built for x86 (because the original project was). ELMAH is the .Net 3.5 x86 version. The IIS7.5 app pool is set to allow 32-bit.
Any idea what I need to do to get this working?
In my case, I had to set the "load User Profile=True" in app pool to make it work.
Steps:
From application pools list, Go to Advanced Settings, Process Model section and set "Load User Profile" to "True".
You will have to go to Add managed handler in the IIS Manager for your virtual web directory.
Request Path will be : elmah.axd
Type will be: Elmah.ErrorLogPageFactory, Elmah
Name: Anything you want it to be identified with.
Note: This settings will be removed every time you publish changes from Visual Studio. So you will have to add it again.