| Details | ![]() |
| QuickDocId | 560 |
| Written by | Imar Spaanjaars |
| Posted | 01/09/2011 11:09 |
| Page views | 10467 |
Are you looking to hire an experienced software developer or .NET consultant? Then get in touch with me through my company's web site at devierkoeden.com
Found an interesting article on this site? Got inspired by something you read here? Then consider making a donation with PayPal.
Back in August 2006 I wrote an article about replacing the built-in Application Services providers (such as the Membership and Roles providers) with a new provider targeting a Microsoft Access database, instead of a SQL Server database. This solution has worked well for many people who didn't have access to SQL Server on their production machine, or couldn't (or didn't want to) spend a lot of money for an extended hosting package that includes SQL Server.
I wrote the article using Visual Studio 2005 and the Microsoft .NET Framework 2.0 which was the bomb at that time. And while you can continue to use the concepts explained in the article in web sites that target ASP.NET 4 today without any modifications (you can easily consume .NET 2.0 DLLs in an ASP.NET 4 web site), you may run into some issues when you also want to compile the Access Providers assembly against .NET 4.
In this article I'll show you how to make the Access Providers work under an ASP.NET 4.0 web site.
If you want to use the Access Providers assembly in an ASP.NET 4 web site, you have at least two options to do it:
In the remainder of this article, I'll show you how to make the Access Providers work with an ASP.NET 4 web site.
With this solution, you either reuse an existing .NET 2 version of the Access Providers assembly, or you create a new one targeting this version of the framework. To create a new version of the assembly, you need a copy of Visual Studio 2005, 2008 or 2010 (the Express editions of 2008 and 2010 would work equally well as they enable you to compile class libraries). Then follow the steps explained in the section "Opening, Compiling and Tweaking the Project" of the original article. This gives you a C# Class Library which outputs an assembly (a DLL file) called SampleAccessProviders.dll. To make sure the assembly targets .NET 2.0, right click the Class Library project in the Solution Explorer, choose Properties and switch to the Application category. In the Target Framework drop down, make sure that .NET Framework 2.0 is selected.
You can now follow the remaining steps from the original article and create a new web site targeting ASP.NET 4. The web site can then reference the .NET 2.0 version of the Access Providers assembly and everything continues to work as described in the article. You may want to continue reading this article, as it contains a few tips about configuring your ASP.NET 4 web site with the Access Providers assembly.
The alternative solution is to upgrade the Class Library project with the Access Providers to .NET 4 as well. If you do this, you'll run into a minor issue. With ASP.NET 4, some types that were previously located in the System.Web assembly have now been moved to their own System.Web.ApplicationServices assembly. This means that if you try to compile the sample code from the Access Providers targeting ASP.NET 4, you'll run into errors like the following:
Error 6 The type name 'MembershipCreateStatus' could not be found. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.
As the error message suggests, the problem can be solved by adding a reference to the System.Web.ApplicationServices assembly. I'll show you how to do this in the following walk through. Additionally, I'll show you how to modify, rather than completely overwrite the web site's web.config (as I showed you how to do in the previous article), to preserve some settings in that file specific to ASP.NET 4. Finally, since even the Visual Web Developer Express editions now support creating class libraries, I'll show you how to create a Visual Studio solution that contains the Access Providers project and your ASP.NET 4 web site so you can manage both from a single Visual Studio solution.

From here, you could follow the steps from the original article. However, one of the steps in that article tells you to overwrite the web.config file in your ASP.NET web site with the one from the Access Providers sample project. If you do that, you wipe out some important ASP.NET 4 settings in that file, reverting your site back to an earlier version of ASP.NET. So, instead of overwriting the web.config file, you need to modify it by following these steps:
<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="AccessFileName" connectionString="~/App_Data/ASPNetDB.mdb"
providerName="System.Data.OleDb"/>
</connectionStrings>
You can delete the ApplicationServices connection string from the config file as it's no longer needed. You can check out the download at the end of this article to see how the web.config file should end up.

For trouble shooting tips and more background, be sure to read the original article discussing the Microsoft Access Providers.
You could easily reuse an existing assembly that was compiled against .NET 2.0 in an ASP.NET 4 web site. If you previously used the Access Providers, you can simply keep using the existing DLL. If, however, you want your entire code base upgraded to .NET 4, you need to make a change in the references of the class library project of the Access Providers. Starting with .NET 4, some of the types used by the Application Services have been moved to their own assembly file which you now need to reference. With the reference in place, you can compile the code into a .NET assembly, and continue to use the Access Providers as you previously did.
The complete source for the Access Providers and the ASP.NET 4 sample web site.
Wonder where to go next?
You can read existing comments below
or you can post a comment yourself on this article.
Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.
I am interested in what you have to say about this article. Feel free to post any comments, remarks or questions you may have about this article. The Talk Back feature is not meant for technical questions that are not directly related to this article. So, a post like "Hey, can you tell me how I can upload files to a MySQL database in PHP?" is likely to be removed. Also spam and unrealistic job offers will be deleted immediately.
When you post a comment, you have to provide your name and the comment. Your e-mail address is optional and you only need to provide it if you want me to contact you. It will not be displayed along with your comment. I got sick and tired of the comment spam I was receiving, so I have protected this page with a simple calculation exercise. This means that if you want to leave a comment, you'll need to complete the calculation before you hit the Post Comment button.
If you want to object to a comment made by another visitor, be sure to contact me and I'll look into it ASAP. Don't forget to mention the page link, or the QuickDocId of the document.
For more information about the Talk Back feature, check out this news item.
| QuickDocId | 560 |
| Full URL | http://imar.spaanjaars.com/560/using-the-microsoft-access-providers-for-membership-roles-and-profile-under-aspnet-4 |
| Short cut | http://imar.spaanjaars.com/560/ |
| Written by | Imar Spaanjaars |
| Date Posted | 01/09/2011 11:09 |