Search code examples
sqldatabaseasp.net-mvc-2aspnetdb

upload ASPNETDB.mdf to shared hosting?


I am developing asp.net mvc2 application and I use asp.net membership provider which uses ASPNETDB.mdf database. I have also my own database and now I wonder how to upload these 2 databases to server? Should I upload them as .mdf file or should I use SQL server? I prefer using SQL server and if someone knows the shortest way to convert and upload these 2 databases it would help me a lot.

Thanks in advance,
Ilija


Solution

  • Funny I just finished doing the same thing. The basic steps are as follows:

    1. From Visual Studio, load your .mdf and choose "publish to provider" to make a .sql file.
    2. Open SQL Management Studio, open a connection to your database and load the sql file. Add a "use yourdbname;" on top to have it output the tables to your database, then run it.
    3. Now you should have the full table structure. What's left is to modify web.config to read the new tables:

    First the membership provider:

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a "
             connectionStringName="ConnectionStringLoginInfo"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression=""
             applicationName="/"
                />
      </providers>
    </membership>
    

    Now the role provider:

    <roleManager enabled="true">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider"
             type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,  Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a "
             connectionStringName="ConnectionStringLoginInfo"
             applicationName="/"
                />
      </providers>
    </roleManager>
    

    And lastly the WebPart provider, if you use it:

    <webParts>
      <personalization defaultProvider="SqlDatabaseProviderDRDBLoginInfo">
        <providers>
          <clear/>
          <add connectionStringName="ConnectionStringLoginInfo"
    
               type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
               name="SqlDatabaseProviderDRDBLoginInfo"/>
        </providers>
      </personalization>
    </webParts>
    

    In this example I called the connection string ConnectionStringLoginInfo, but whatever you name it, make sure you set it in the connection strings part. Not gonna paste that too :)

    This all took me way more than I care to say, but when I saw my app working flawlessly with the App_Data folder deleted, that was quite the moment!