Connecting VB To Web Host

In this tutorial i will be showing you how to connect a data application to a web server.
This will allow your end users to work with your application data in whatever way you desire.
Before i get started i should point out that some hosts may work differently when attaching your databases.


Some may require you to upload the database itself to the server and some may allow connection via SQL Server Management Studio.
In this tutorial i will be using Winhost as the hosting server.
Visit www.winhost.com to get more information and to purchase your hosting package.
I’m using the Winhost Max package ($9.95/Mo).

Note!
This tutorial was created to show users how to connect their desktop application to a server hosted at winhost.com
This tutorial does not cover the uploading proccess of your application.
The uploading proccess can be done using the Click Once feature built in to Visual Studio

Something Useful

This tutorial uses the following requirements and they should be used by you to ensure it will work correctly.

  • Visual Studio 2010
  • .NET Framework 4.0
  • SQL Server Management Studio 2008

With that out of the way now, lets get started on the tutorial.

Step 1 – Setting up the server to work with this

Once you have your host created at Winhost navigate to the control panel and login
After logging in click on Sites tab.
You should now see a list of domains you have assigned to your account

Click on the Manage link and that will take you to the management section of that domain.
This section allows you to configure your site.


The first thing we are interested in is configuring the .NET framework we want the server to use.
Click on the ASP.NET Version icon
From the ASP.NET Framework Version dropdown list choose 4.0 than click Update.
Now our server is ready to use applications created using the .NET Framework 4.0

There’s one more thing we need to set up…A database.
Click on the MS SQL 2008 icon.
Click the Add button.
In the Database Name field type in the name of the database you want to create.
You can type in any name you want.
Now click Create.

Now you have your database set up, we can now minimize our web browser for now and load up Visual Studio.
We will need to go back into our control panel once we’re done with our application to grab the details of our database.

Step 2 – Creating your data application

Once you have VS open you can go a head and create your application.
Once your application is complete we will need to modify the Connection String in the app.config file.

Step 3 – Modifying the App.config file

Now that you have your application created we need to use the connection string that we were given when we created our database on Winhost.
So go back to your control panel and go back to your MS SQL 2008.
Click on the Manage link to manage the database.
You should now see your database details, such as

  • Server name
  • Database name
  • Database user etc.

You need to grab the complete connection string

“Data Source=???:???.winhost.com;Initial Catalog=DB_8754_databasename;User ID=DB_8754_databasename_user;Password=******;Integrated Security=False;”

Jump back to your project and open the App.config file.
You should see a connection string within the <connectionStrings> attribute.
Replace everything after connectionString= with the connection string you coppied from your control panel.
The complete connection string should look something like this

connectionString=”Data Source=???.winhost.com;Initial Catalog=DB_8754_databasename;User ID=DB_8754_databasename_user;Password=password”
providerName=”System.Data.SqlClient” />

Now go a head and save your project.
We are now ready to attach our database to the server.

Step 4 – Attaching our database to the server

In your Visual Studio click on the Server Explorer tab.
You should see your database listed here.
Right click on it and choose Publish To Provider
Your database should be selected by default, if it isn’t go a head and select it.
Now you can click Next to choose a path where you want the script file to be generated to.
You can now click Finish and it will start gether all the Objects.
Once this is complete successfully you will see a .MDF.sql file wherever you told it to download to.
The next thing we need to do is tell the server our database is being hosted on to use this database, so lets do that now.

  • Open SQL Server Management Studio
  • In the Connect to Server dialog just click Cancel for now.
  • At the top click on File => Open => File
  • Browse for the .MDF.sql file you downloaded earlier.
  • You will now be asked to connect to a server.
  • Go back to your Winhost control panel => Site Manager => MSSQL 2008
  • Click on the Manage link beside your database
  • Copy the Database Server name and go back to SQL Server Management Studio and paste it in the Server Name field (See screenshot 1.1)
  • Go back to your control panel and grab the Database Username and paste that in to the Login field
  • Now put in your password (This is the same as your login password to the control panel)
  • Also make sure Authentication is set to SQL Server Authentication and click Connect
  • You will now see a list of queries. (See screenshot 1.2)
  • At the very very top of that window type in the following

USE databaseName
GO

  • Now at the top, click on Execute
  • The command should be executed successfully

Screen 1.1

Screen 1.2

Your database is functional on your server and is now ready for use.
Now if you go back to your VS => Server Explorer and you create a new database connection, you will now be able to interact with the database that’s on the server.
When you make changes to the database they will be applied automatically on the server end.
You can also do your Database Management from SQL Server Management Studio by connecting to it the same way we did previously.
All that is left now is for you to upload your project to your server.
I hope you enjoyed this tutorial and i hope it has helped you out in some way.

0saves
If you enjoyed this post, please consider subscribing to the RSS feed to have future articles delivered to your feed reader.

2 Responses to Connecting VB To Web Host

Leave a Reply

Donations

Donations help to produce more content, more and better video tutorials

Youtube Channel Of The Week

JD Site Care chose
GoVisualTeam

Advertisement