0% found this document useful (0 votes)
37 views5 pages

Microsoft SQL Server Connection String

Uploaded by

muxumedc781
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Microsoft SQL Server Connection String

Uploaded by

muxumedc781
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

VB.NET ADO.

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.

ADO.NET Data Providers


The .Net Framework includes mainly three Data Providers for ADO.NET. They are the Microsoft
SQL Server Data Provider , OLEDB Data Provider and ODBC Data provider. You can see from the
following links how these Data Providers making connection to the specified data Sources.
SQL Server Connection
OLEDB Connection
ODBC Connection

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.

ADO.NET Connection Object


The Connection Object is a part of ADO.NET Data Provider and it is a unique session with the
Data Source. In .Net Framework the Connection Object is handling the part of physical
communication between the application and the Data Source. Depends on the parameter
specified in the Connection String , ADO.NET Connection Object connect to the specified
Database and open a connection between the application and the Database .
When the connection is established, SQL Commands may be executed, with the help of the
Connection Object, to retrieve or manipulate data in the Database. Once the Database activity is
over, Connection should be closed and release the resources.

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.

ADO.NET ExecuteNonQuery in SqlCommand


Object
ExecuteNonQuery() is one of the most frequently used method in SqlCommand Object and is
used for executing statements that do not return result set. ExecuteNonQuery() performs Data
Definition tasks as well as Data Manipulation tasks also. The Data Definition tasks like creating
Stored Procedures and Views perform by ExecuteNonQuery(). Also Data Manipulation tasks like
Insert, Update and Delete perform by ExecuteNonQuery().
The following example shows how to use the method ExecuteNonQuery() through SqlCommand
Object.

ADO.NET ExecuteReader in SqlCommand


Object
ExecuteReader() in SqlCommand Object send the SQL statements to Connection Object and
populate a SqlDataReader Object based on the SQL statement. When the ExecuteReader
method in SqlCommand Object execute, it instantiate a SqlClient.SqlDataReader Object.
The SqlDataReader Object is a stream-based, forward-only, read-only retrieval of query results
from the Data Source, which do not update the data. The SqlDataReader cannot be created
directly from code, they created only by calling the ExecuteReader method of a Command
Object.

How to ADO.NET DataReader


DataReader Object in ADO.NET is a stream-based, forward-only, read-only retrieval of query
results from the Data Source, which do not update the data. The DataReader cannot be created
directly from code, they created only by calling the ExecuteReader method of a Command
Object.

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

You might also like