ilija veselica
ilija veselica

Reputation: 9574

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

Upvotes: 1

Views: 2376

Answers (3)

Waleed Al-Balooshi
Waleed Al-Balooshi

Reputation: 6406

As a supplement to Blindy's answer I wanted to mention that another way to configure the providers is to change the connection string settings of the default ConnectionString used by most of the providers, which is LocalSqlServer. To do this you just override that particular ConnectionString in your web.config like so:

<connectionStrings>
    <clear />
    <add name="LocalSqlServer" connectionString="change this to be the details of your host database" providerName="System.Data.SqlClient" />
</connectionStrings>

Also, if you don't want to clear the entire connectionStrings section you can just remove the particular connection string like this:

<connectionStrings>
    <remove name="LocalSqlServer" />
    <add name="LocalSqlServer" connectionString="change this to be the details of your host database" providerName="System.Data.SqlClient" />
</connectionStrings>

This works, because all providers that default to using Sql Server for their Data Store - such as the membership provider - use the "LocalSqlServer" connection string by default. Thus, if you override it, you don't have to change each provider to point to a different Connection String.

Also, for security reasons, you might want to look into encrypting the connectionString section of your web.config file. The following two articles provide more info.

Encrypting and Decrypting Configuration Sections

How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA

Upvotes: 1

Phil.Wheeler
Phil.Wheeler

Reputation: 16848

Your simplest option for a hosted solution (i.e. your hosting plan is not a Virtual Private Server) is to generate SQL scripts of your database, exporting these to *.sql files and then run them in your hosted SQL connection.

I would normally connect to my web host's SQL instance using SQL Server Management Studio and either open or paste in the scripts generated by my local copy.

Depending on whether or not your web host provides the service, you might also be able to use the "Publish to provider..." option in Visual Studio.

Upvotes: 1

Blindy
Blindy

Reputation: 67380

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!

Upvotes: 6

Related Questions