The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Using a shared database with the ASP.NET membership provider in a Windows forms application
I had a few questions about the article "Using the ASP.NET membership provider in a Windows forms application" I wrote about moving the membership data. In short what people wanted to was not have a local ASPNETDB.MDF SQLExpress database in the App_Data directory but retrieve the data from another, central, SQL Server.
 
In fact that makes perfect sense because the local ASPNETDB.MDF database is exactly that, a local database that cannot be shared between different people running the application.
 
Fortunately the solution is simple and consists of two parts:
  1. Creating the required database structure somewhere else.
  2. Redirecting the Membership provider to the new database.
 
Creating the required database structure somewhere else
To create the required database structure you can use a standard SDK tool called aspnet_regsql.exe. This will either run in UI mode if you just start it and it will simply create a complete structure in an existing database you point it to. Using command line options you get more control over what it does. This mode allows for creating specific subsets of the structure like just the membership and role tables.
 
Redirecting the Membership provider to the new database
Again this is easy to do. Create a connectionStrings section in the app.config file. By default the connection string LocalSqlServer is used and all we have to do is remove the original value and add a new one. Another option would be to to change the connectionStringName property when we added the AspNetSqlMembershipProvider and add that to the  connectionStrings section.
 
<connectionStrings>
   <removename="LocalSqlServer" />
   <addname="LocalSqlServer"
    connectionString="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True"/>
</connectionStrings>
 
 
Maurice de Beijer
Published Mon, Mar 6 2006 12:09 by Maurice
Filed under: