Saturday, October 1, 2011

Connecting a database I

Any application that needs to store or retrieve data, needs to use databases. Since we developers make the application layer, it is for us to connect the application to the database and to provide the queries to affect the data.

Here is what little insight i can provide into the databases and their connecting schema. For any suggestions or doubts, please contact me at nardz07@gmail.com.

First and foremost, databases may be operating system dependent, like MS ACCESS and SQL SERVER, or independent like ORACLE or MYSQL.


In this post, let us simply look at these databases and how to define a generic database connection using the MS Visual Studio tools.



Now, to connect databases, microsoft provides namespaces like Ole-db, Odbc, SqlClient, OracleClient for accessing and managing data from diverse sources. These top-level namespace and a number of the child namespaces together form the ADO.NET architecture and ADO.NET data providers.


Let us understand each one separately:


OLE-DB stands for Object Linking and Embedding, Database. This basically allows the application to connect any object database, which may or may not include SQL. So, even excel spreadsheets can be connected using OleDb. Mostly, we connect small scale query oriented databases like Microsoft Access by using this namespace.



ODBC stands for Open Database connectivity, which is a standard software interface for accessing database management systems (DBMS). The designers of ODBC aimed to make it independent of programming languages, database systems, and operating systems. Thus, any application can use ODBC to query data from a database, regardless of the platform it is on or DBMS it uses. We generally use it to connect to Pl/Sql databases, and Oracle databases.


SqlClient is a software interface which solely connects an application to Microsoft SQL Server database. This is hence not application or even OS independent.



OracleClient is a similar database connectivity interface which solely serves for Oracle databases and non other. However, as oracle databases are OS independent, so is OracleClient.


Now, I am presuming all readers know how to create a database, so I will not elaborate on that. Let us start with connectivity in VS2008:


First open the Server Explorer and right click on connections, select add a new connection:




The following dialog will open:




Either input the name of your said database into the file area, or select the right type of database by clicking change:




Select the database type that your database has made, so the appropriate drivers be placed. On pressing OK, the previous dialog will be re activated with said changes. Add the database username and password in case it is locked. Press okay when you are done, and presto chango, your database has been added to the application:




Once this is done select the database, and go to the properties window. Click on the connection ID, and you will see the entire connection string that defines the database connection:


Copy this string, because this is the string that must be added to the coding whenever we need to call the database. But more on that later.


Your suggestions will be most welcome. If there is anything you want me to explain, I'll make sure to look into it. Learning is a two way street :P ;) Mail me. Till next time!

2 comments:

  1. Thats a usefull post ! Now my college is very poor to give me access , oracle or sql things. Wat should i do for MySql ! its free na :)

    ReplyDelete
  2. Thats a easy way for data connectivity

    ReplyDelete