views:

636

answers:

2

Is the "asp.net membership provider" portable? Do I have to run the aspnet_regsql.exe to set it up for every new machine?

I imported the membership provider database to Visual Studio Database Edition and checked into my source control, and redeployed it to a different dev machine. From the new machine, I got the following error. How do I fix this? Thanks!

The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'. However, the current database schema is not compatible with this version. You may need to either install a compatible schema with aspnet_regsql.exe (available in the framework installation directory), or upgrade the provider to a newer version.

+1  A: 

It is "portable" as long as you have Framework 2.0 or upper in the new dev environment and access to the DB containing the schema.

The aspnet_regsql.exe application is only for generating the db schema. The real deal happens in the web.config when specifying your provider.

As long as you have the .mdf file reference in the connection string or the DB containing the membership provider schema, everything should work fine.

Connection String:

<connectionStrings>
     <add name="LocalSQL" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=YourCatalog;Persist Security Info=True;User=sa;Password=password" providerName="System.Data.SqlClient"/>  
    </connectionStrings>

Membership Provider:

<membership defaultProvider="DefaultProvider" userIsOnlineTimeWindow="30">
      <providers>
       <clear/>
       <add name="DefaultProvider" connectionStringName="LocalSQL" applicationName="DefaultApp" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Encrypted" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </providers>
     </membership>
Raúl Roa
A: 

The SQL membership provider is needed for every database. The provider registration process creates certain tables within the database. If those tables are not there, you'll get the errors above.

Since the tables are created in the database, you can have as many different applications or development machines as you want to share the single SQL database.

But if you want another provider instance, because you have a different application or need to talk with another SQL database, then you'll need to register (create the tables) again. Another possibility would be to use SQL replication to copy the tables from one database to another.

What is likely is that your application needs to modify the web.config file to make sure it has the right connection string to an existing SQL database.

Tommy Hui