Database Hosting on Shared Database Server in ASP.NET


Introduction

In most of the cases we use to think, database hosting is very simple like as we host on our localhost. But remember, it is very different from localhost database hosting. We have lots of way to host the database on shared database server but this article will explain you the simplest way to work on Shared Database Hosting Sever.

Aim of the Article

In this article we will create a telephone directory on our localhost and then we will publish it to shared database server that is to database provider.

Prerequisite

You should have the following things: 

(i) VB 2005/2008, Visual Web Developer 2005/2008 
(ii) SQL Server Management Studio 
(iii) Microsoft SQL Server Database Publishing Wizard 

Before getting started, install above all products successfully as in given order.

Creating Database in ASP.NET

At the very first, we have to create a web application which will display the telephone directory. Add New Item to our web application as named Default.aspx and select the Language as Visual Basic. 
 

In above image, we can see our pages like Default.aspx, Default.aspx.vb, web.confi and a empty App_Data directory in the root of application. But we don’t have any Database in App_Data directory, so let’s create it. 

To create database in ASP.Net, point the cursor in Database Explorer, right click on App_Data directory to Add New Item and in appeared window select SQL Database to create Database.mdf database file. 
  

Now open point the cursor on Database Explorer, you can see here the added database. Now expand the Table option there, you will find nothing there because we have not added any table still. So, let’s add new table to our web application. 

To add new table in ASP.Net Database Explorer, right click on Table and select the Add New Table option. Now you will see the following screen with having any field. 
  

Still we don’t have any field there, let’s add it as given in image below. Save this table using name ‘telephone’. 
  

Now we have a database and a table, you must like now to enter some data there. So, let’s enter some data in database table. 

To add data in table, right click on ‘telephone’ table in Database Explorer. It will show you the table and you have to enter some data for table. The image given below will explain you all about. 
  

Now we have database, table and data also. You must now like to display data on web application form. Let’s add it on form. 

To add table’s data on form simply drag the ‘telephone’ table from Database Explorer to application form. Here is a screenshot. 
 

Now to view the actual data on form run the application. You will see the following data there. 

Now we have everything complete on running on our localhost. The main issue is arising here, how to run it on Shared Database Severs? It is now very different from still we did. Let’s step out towards Database Hosting on Shared Database Server. 

I expect that you have installed all applications discussed above and running well on your localhost. 

To publish database on hosting server, we have lots of way but the simple way I am mentioning. We have to create a query file on our localhost for our database and will be executed on Shared Database Server. Take a look at screenshot. 

To create query file which has extension .sql, right click on ‘Database.mdf’ file in Database Explorer and now click on ‘Publish to Provider’ option. 
  

Now follow the different screenshots to perform your task. 
 
  
  
  
  
  

Now click on close button. Check in you hard disk drive which you will be given as script file location, there should be a ‘database.sql’ file. Let’s take a look, how to publish it on Shared Database Server. 

Note: Now internet connection required to open the remote database server. 

To publish database file we have to execute the ‘database.sql’ file on shared database server. You should have your own credentials provided by your hosting company. Basically any hosting company serves many customers like you. They use to create database for you on your request. They use to decide that what will be the name of database file because they have to manage the database from hacking, virus or from any unauthorized usage. I am just showing you the way to execute using my own credentials and screenshots. 

Now open an application named ‘SQL Server Management Studio Express’ as we have installed on above request, usually you will find this application under ‘Microsoft SQL Server 2005/2008’ in start menu. In appeared window type your own credentials. ‘Sever Name’ is usually an IP address, authentication will be as ‘SQL Sever Authentication’ and Login, Password and one more thing is database name will must have. At the end click on ‘Connect’ button. 
  

It will take some time to map the location and verify the credentials provided by you. In the image given below you can see my database name as selected in left panel. There too databases but I have only authority for one which is selected. 
 

Now click on ‘New Query’ option it will open you a new page. Open your ‘database.sql’ file in Notepad and copy the entire content and paste it there. Now click on ‘Execute’ option above to create the same database tables on shared database server. 
 

Now your database is also available on Shared Database Sever. You can use it on your application to run. 

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Lambda two tables and three tables inner join code samples