Tuesday, May 3, 2011

How To Upload a Database to a Virtual Hosting Server

How To Upload a Database to a Virtual Hosting Server? Its easy!

But I'm jotting this down to avoid having to figure it out again in the future!

For the record, I'm using www.winhost.co.za as my hosting company which gives me a PLESK interface, developing in ASP.net with C#, and using a Microsoft SQL Server database. The process should be similar on other hosting provider systems.

Alright, lets get our hands dirty:

  1. Create your database in Visual Studio. Don't use the generic name (aspnet.mdf) for the membership database, because when you have a virtual hosting option each database on the server must be unique. Chances are another website using the same host as you already used the generic name.
  2. After creating your database in filling it with your content, upload it via FTP to your App_Data folder (the DB's MDF and log file)
  3. Now log in to your PLESK panel and create a MS SQL Server database there, too.
  4. For your new database in PLESK, create a new username and password. Write down these details.
  5. Now, contact your hosting provider to ask them to extract your database. Give them the location of the the database (App_Data\YourDataBase.mdf). Do this as soon as possible, because your ISP support team may be a bit slow for you!
  6. When they let you know they're done, you can almost relax!
  7. In the meanwhile, go to PLESK again and configure your ASP.net settings to replace the connection string. I use this:

    Data Source=(local);Initial Catalog=MYDATABASE;User Id=THEUSERNAME;Password=THEPASSWORD;

    All the CAPITOL words must be replaced with your details. Replace MYDATABASE with your database name (without its extension, .mdf). The user ID an Password are those create in PLESK at step 4
Now test your website to see if the database is working! It should!
Having trouble? Too bad! But take note of a few things that might help you:
  1. After your service provider restored your uploaded database, access it from PLESK to see if all the tables that should be there, are indeed online
  2. Always check that the hosting company supports the database version you use
  3. In PLESK, be sure to create the same database type that you have on your project (for instance, MS SQL Server and not MySQL)
  4. Careful not to upload your web.config file, which contains the wrong connectionstring after you replaced the connection string in PLESK. Uploading the new web.config file will replace your connection string in PLESK, and your web application won't be able to connect to your database
Hope this helps you!

    No comments:

    Post a Comment