Microsoft SQL Server Connection String
Microsoft SQL Server Connection String
NET
ADO.NET is a data access technology from Microsoft .Net Framework , which provides
communication between relational and non-relational systems through a common set of
components. ADO.NET was built for a disconnected architecture, so it enables truly
disconnected data access and data manipulation through its Dataset Object, which is
completely independent from the Data Source.
The two key components of ADO.NET are Data Providers and DataSet . The .Net Framework
includes mainly three Data Providers for ADO.NET. The Microsoft SQL Server , OLEDB and ODBC
are the main Data Providers in the .Net Framework. In the following pages you can see each
component of ADO.NET in details with source code.
ADO.NET ConnectionString
Connection String is a normal String representation which contains Database connection
information to establish the connection between Datbase and the Application. The Connection
String includes parameters such as the name of the driver, Server name and Database name , as
well as security information such as user name and password. Data providers use a connection
string containing a collection of parameters to establish the connection with the database.
The .NET Framework provides mainly three data providers: Microsoft SQL Server, OLEDB and
ODBC. Here you can see how to make connection string to these ADO.NET Data Providers.
Microsoft SQL Server Connection String
connetionString ="Data Source = ServerName; Initial Catalog = Databasename; User ID =
UserName; Password=Password"
OLEDB Data Provider Connection String
connetionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =
yourdatabasename.mdb;"
ODBC Connection String
connetionString = "Driver = {Microsoft Access Driver (*.mdb)}; DBQ =
yourdatabasename.mdb;"
Note : You have to provide the necessary informations to the Connection String attributes.
In the following section you can see how to these ADO.NET Data Providers establish connection
to the Databse in detail.
The four Objects from the .Net Framework provide the functionality of Data Providers in
ADO.NET. They are Connection Object, Command Object, DataReader Object and DataAdapter
Object. The following link shows in details about these Objects.
In ADO.NET the type of the Connection is depend on what Database system you are
working with. The following are the commonly using the connections in the ADO.NET
ADO.NET Command
The Command Object in ADO.NET executes SQL statements and Stored Procedures against the
data source specified in the Connection Object. The Command Object required an instance of a
Connection Object for executing the SQL statements. That is, for retrieving data or execute an
SQL statement against a Data Source, you have to create a Connection Object and open a
connection to the Data Source, and assign the open connection to the connection property of
the Command Object. When the Command Object return result set, a Data Reader is used to
retrieve the result set.
The Command Object has a property called CommandText, which contains a String value that
represents the command that will be executed in the Data Source. When the CommandType
property is set to StoredProcedure, the CommandText property should be set to the name of
the stored procedure.
Click the following links to see some important built in methods uses in the Command Object to
execute the SQL statements.
DataReader = Command.ExecuteReader()
DataReader Object provides a connection oriented data access to the data Sources. A
Connection Object can contain only one DataReader at a time and the connection in the
DataReader remains open and cannot be used for any other purpose while data is being
accessed. When started to read from a DataReader it should always be open and positioned
prior to the first record. The Read() method in the DataReader is used to read the rows from
DataReader and it always moves forward to a new valid row, if any row exist .
What is DataAdapter
DataAdapter is a part of the ADO.NET Data Provider. DataAdapter provides the communication
between the Dataset and the Datasource. We can use the DataAdapter in combination with the
DataSet Object. That is these two objects combine to enable both data access and data
manipulation capabilities.
The DataAdapter can perform Select, Insert, Update and Delete SQL operations in the Data
Source. The Insert, Update and Delete SQL operations, we are using the continuation of the
Select command perform by the DataAdapter. That is the DataAdapter uses the Select
statements to fill a DataSet and use the other three SQL commands (Insert, Update, delete) to
transmit changes back to the Database. From the following links describe how to use
SqlDataAdapter and OleDbDataAdapter in detail.
SqlDataAdapter