Lesson 22.1 – Installing MS SQL Server on your computer

Adding SQL to SuperAdventure

When we add the SQL Server code to SuperAdventure, we will check to see if the database exists. If it doesn’t, the program will continue to use the XML file to save the player’s game data.

This way, people can still use the program if they don’t want to install SQL Server.


Which SQL database engine?

For these SQL lessons, I will use Microsoft SQL Server 2014.

If you do not have, or cannot install, Microsoft SQL Server, you can use one of the other SQL database engines available. Two other popular SQL database engines are: PostgreSQL and MySQL.

If you use one of the other SQL database engines, there will be a few small differences. I will try to mention the areas that work different from Microsoft SQL Server. If you see a problem, please leave a comment below the lesson. I will try to find an answer to get your SQL engine working.


Preparing to install Microsoft SQL Server

It’s best to install SQL Server before installing Visual Studio. However, if you are at this point in the lessons, you already Visual Studio installed. So, we will install SQL Server now.

Before installing Microsoft SQL Server, you need to install version 3.5 of the .NET Framework. You even need to do it if you have a newer version installed. SQL Server has some specific things it needs from version 3.5.

The video below shows how to install .NET 3.5.

Or, you can open your Control Panel, go to Programs and Features, select “Turn Windows features on or off”, and check the box for “.NET Framework 3.5 (includes .NET 2.0 and 3.0)”. This will try to install the 3.5 Framework from your Windows installation disks, or from the Internet.


Microsoft SQL Server installation video

Here is a video that shows how to install Microsoft SQL Server 2014.



Parts of SQL Server

There are usually two things you install, when you install any SQL program – the database engine and the management tool.

The database engine is the program that runs in the background. It’s always running, but it does not have a user interface. This is what your program uses to save and retrieve data.

The management tool has a user interface. It lets you easily manage your databases. Microsoft named theirs, “Microsoft SQL Server Management Studio”. This is the program we will use to create the tables in our database. If you use a different SQL engine, they will probably have their own management program.


Next lesson: Lesson 22.2 – Creating database tables from classes

Previous lesson: Lesson 21.4 – Completing the trading screen

All lessons: Learn C# by Building a Simple RPG Index

14 thoughts on “Lesson 22.1 – Installing MS SQL Server on your computer

    1. Try this:

      In the Visual Studio menu, select Tools -> Connect to Database…
      Select “Microsoft SQL Server Database File”
      Click “Continue”
      Enter “SuperAdventure” for the database name
      Select “Use Windows Authentication”
      Click “OK” and create the database
      This should create your database.

      From the Visual Studio menu, select View -> Server Explorer, and you should see your database in “Data Connections”.

      To add tables, right-click on the “Tables” folder, and select “Add New Table”.
      You can create the tables by copying the scripts into the “T-SQL” area, or by manually entering them in the [Design] area.

      Please let me know if that works for you, or not.

  1. Hello, I have a little question and sorry if my english is bad.
    After I updated all windows think from Windows Update I cannot seen this: “.NET Framework 3.5 (includes .NET 2.0 and 3.0)” in my Windows Features. By the way I have Windows 7.
    What should I do? the single think .NET i see is: “Microsoft .NET Framework 3.5.1
    Thx in advance.

    1. .NET Framework is an updated version of 3.5. So, it should work. Did you try to install SQL Server? If you tried to install SQL Server, did you see any errors?

        1. If you use PostgreSQL, you will need to make some changes in the next lessons.

          To connect to the database, you might need a different connection string, or to use Npgsql (http://www.npgsql.org/). The scripts to create the tables, and insert/read/delete records in the database (Lessons 22.2 and 22.3) might also be different. If you have problems with those, please tell me, and I will try to help.

  2. Everything is fine for moment but when i copy-paste the code from 22.2 in postgresql I put it in “SQL” expansion (because i cant see anything else) and after that I cannot rename my table or to create it.

    1. Try using this code, and tell me if it works. If it does not work, please take a screenshot, so I can see the problem.

      CREATE TABLE SavedGame(
      CurrentHitPoints int NOT NULL,
      MaximumHitPoints int NOT NULL,
      Gold int NOT NULL,
      ExperiencePoints int NOT NULL,
      CurrentLocationID int NOT NULL

  3. thanx you so much it work now, but it is a problem if instead of CurrentHitPoints, MaximumHitPoints my program change automaticaly in lower case all upper case? Sorry for many question but I am a tottaly beginer.

    1. Are you talking about the column names, in the SQL database? If yes, for SQL databases, a column named “CurrentHitPoints” is the same as a column named “CURRENTHITPOINTS” or “currenthitpoints”. SQL is not like C#, where the difference would create a problem.

    1. You don’t need to use SQL. You can use the XML file. But, if you want to learn the basics of how to use SQL, this lesson will show you how to connect the game to a SQL database.

Leave a Reply

Your email address will not be published. Required fields are marked *