Connecting to ms sql server 2005

In this tutorial, I’m going to show you how to connect your application to microsoft sql server 2005.


After downloading and installing the requirements on your computer, the first thing that you have to do is to create a sample application, launch visual studio and create something like this:


If you just want to know how to connect, then scroll down to your point of interest.

After that, open up Microsoft SQL Server Management Studio, and you’ll see something like this:


The server type must be set to database engine.

The server name must be set to the name of your computer then forward slash, then the kind of server. In this case, I’m using SQL Express.

If you have password on your computer, then you should place it also.

If you don’t know the name of your computer. Just click on the start orb then right-click on my computer. Then select properties.

After that, scroll down a bit and you’ll see something like this:


In my case, the computer name is Vongola. So you just have to change that to all caps. Like the one you saw above.

I’m using Windows 7. So it might be a little bit different if you’re using Windows XP. It should be the same if you’re using Vista.

If everything goes well, you’ll be seeing something like this:


First thing that you’ll need to do in here, is to create a new database.

To do that, just right click on Database then select ‘new database’. Just supply the database name that you want then click ok.

After that, you should now be able to see your newly created database on the left-hand pane:


I named mine to ‘testdb’. You should see a different name depending on what you have typed earlier.

Then you have to add some tables on your database. To do that, just expand ‘testdb’. Then you’ll see ‘tables’. Right click on that and select ‘new table’. Add the necessary fields. Then press ctrl+s on your keyboard. Name the new table to whatever name you want then click ok.


Back to visual studio, what you’ll want to do next is to add a new class for inheriting methods that we will be using to extract and use data from the ms sql database. To do that, just right click on ‘windows application 1 in the right-hand pane’. Then select ‘add’ then click on ‘class’.


Then put the code that you see below, in the newly created class:


Then put this on your main form(the one with the GUI):

Public Class Form1
    Dim p As New parent
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click = TextBox1.Text
        p.course = TextBox2.Text
    End Sub
End Class

You will get the connection string for sql server 2005 from here.  You’ll need a different connection string for every kind of database that you wish to connect your app to. But the process and the code used to manipulate different kinds of database is almost always the same.

I’ve already included comments in the code, to show you what  those codes do.

1 thought on “Connecting to ms sql server 2005

  1. Pingback: database connection basics part 1 « Data Integrated Entity

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s