Databases

In this section you will learn how to access a database from inside the .NET Framework application.

As Microsoft data access technologies change very frequently, there are more ways to work with databases in the .NET Framework. We will discuss two most commonly used – the ADO.NET technology and the Entity Framework.

Both of these technologies have their advantages and their disadvantages. The ADO.NET works on a much lower level, communication with the database directly. While it sometimes takes more work to be able to use the base ADO.NET classes in real world applications, these classes provide the best performance.

The Entity Framework, on the other hand, has you mostly covered. It has been designed so that it is very easy to use. It does many things behind the scenes and lets you concentrate on working with the data. The Entity Framework could be considered a higher level tool for working with the database. In fact, the framework itself uses the ADO.NET classes to communicate with the database internally.

Microsoft SQL Server

Even though you can connect to just about any database server from within the .NET Framework application, let us take a closer look at two database servers coming directly from Microsoft.

Microsoft has its own database server called Microsoft SQL Server. There are a couple paid-for editions but there is also a free Express edition. The Express edition comes with some technical limitations, such as that the maximum size of a single database cannot exceed 10 GB or that only up to 1 GB RAM can be used by the database server itself. For most small applications, these limitations are all right.

To manage an SQL Server instance Microsoft provides a tool that very much resembles Visual Studio itself. This tool is called Microsoft SQL Server Management Studio and allows you to manage both, local as well as remote database servers. It makes many common tasks, such as creating new databases, new tables, new stored procedures, executing SQL queries, etc., much easier.

Microsoft Azure SQL

As opposed to the full version of Microsoft SQL Server that you can install on your own computer or your own server, Microsoft Azure SQL is a database server running in the Microsoft Azure cloud and is completely managed by Microsoft itself. While there are couple differences between these two versions of SQL server as far as functionality is concerned, the main difference, of course, is that you cannot install Microsoft Azure SQL on your own server. It always runs on Microsoft servers in the Azure cloud and the whole SQL server is provided as Platform as a Service (PaaS) offering.

My C# .NET Database

To make running all of the examples on this website easier, they were all prepared to use Microsoft Azure SQL database. This way you do not need to install the full blown Microsoft SQL server on your machine to follow up with them.

All you need to do is to be able to access a sample database that has already been prepared in Microsoft Azure SQL for you. You will need the following connection information:

  • Server: ookj3vjulf.database.windows.net
  • Database: MyCSharpDotNet
  • User: dbuser
  • Password: Databa5e

With these credentials you will get a full read-only access to all of the database tables, an execute permission on an already defined stored procedure as well as read-write access to a special table called WritableRows.

Apart from this WritableRows table, the sample database is a simplified version of the Northwind sample database from Microsoft. The following picture shows all the tables and all their relations as they are defined in a Northwind sample database:

Make sure you have this structure handy when you follow the examples.

Select one of these topis to learn more:


Should you have any questions or found a mistake that needs correcting, feel free to send an email to: info [at] mycsharp [dot] net


Advertisements :