Changing from an asp.net mvc LocalDb to an SQL server

Discussion in 'Databases' started by Sachelis, Aug 7, 2013.

  1. I developed a small website using Visual Studio Express 2012 for Web. The website runs on my local machine. The site has two connection strings in its web.config file:

    HTML:
        <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcSaf-20130711122034;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcSaf-20130711122034.mdf" providerName="System.Data.SqlClient" />
        <add name="MvcSafContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\SAF_Orgs.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    
    After deploying the website (using Web Deploy), I can view the pages that don't access the databases. However, if I attempt to log in (i.e., visit http:://myweb.com/account/login), I get a System.ComponentModel.Win32Exception and then an SqlException. That makes sense, because as I understand it, Winhost.com can't support an mdf database (although I did publish them, to).

    I new, really new, to SQL servers... Can I have Visual Studio create the SQL databases on the WebHost.com servers and create the new connection strings? I saw this Winhost.com kb article about deploying, but I don't understand how I transition from the LocalDB to the SQL server. Microsoft has this article about deploying, but it's many, many hours of reading, requires a 600mb download to create a script, and is closely related to the one sample it has you deploy. I'm looking for step-by-step instructions that show me how to move my existing database structures to Winhost.com and to modify my connection strings.

    Thanks!
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    For Microsoft SQL Server databases, you will need to create a backup locally and then upload the .bak file somewhere in your hosting account. We recommend placing it in the /_database folder. You will first need to create the database prior to restoring it. To create the database:

    1) Log into the Winhost Control Panel at https://cp.Winhost.com
    2) Click on the Sites tab.
    3) Click on the Manage link next to the site you want to manage.
    4) Click on the MS SQL Manager button.
    5) Click on the Add button.
    6) Select the database version in the drop down list, name the database, set the quota, and then click on the Create button.

    To restore the database:

    1) Click on the Manage link next to database you just created.
    2) Click on the Restore link.
    3) Provide the path to the backup file you uploaded and click on the Restore Backup button.

    After that, you just update the connecting string in your web.config file to the one we provide in the Control Panel.
     
    Last edited by a moderator: Oct 14, 2015
    Michael likes this.
  3. Thanks.

    Where in the control panel are the connection strings listed?
     
  4. Found it. After adding the sql databases, select MS SQL Manager and then Manage.
     
    ComputerMan and Elshadriel like this.
  5. ComputerMan

    ComputerMan Winhost Staff

    Thank you for posting what you found. I'm sure it will help someone else when trying to find the connection string for a SQL database they created in our control panel.
     
  6. Thanks for sharing, this has been very useful to me.
     
    ComputerMan likes this.

Share This Page