Professional Documents
Culture Documents
ASP .Net Database Connectivity Presentation
ASP .Net Database Connectivity Presentation
• ADO.NET
• Using any ORM (Entity Framework, NHibernate etc.)
ADO .Net
• Database connectivity and functionality are defined
in the ADO.NET namespaces of the .NET Framework.
• ADO.NET comes with several data providers,
including SqlClient, OleDB, and ODBC.
• .NET framework also provides in-memory data access
using LINQ. In this article
• SQL data provider of ADO.NET is defined in the
System.Data.SqlClient namespace
System.Data.SqlClient
• System.Data.SqlClient namespace of .NET Framework
contains all of the classes required to connect to
a SQL Server database and read, write, and update.
• The namespace provides classes to create a database
connection, adapters, and SQL commands that provide
the functionality to execute SQL queries.
Steps to connect database using ADO.Net
1. Declaring connectionStrings in web.config file
2. Establish the Connection
a. Get connection string from web.config file
b. create new SqlConnection object to connect
database by using connection string from
web.config file
c. Open the connection
3. Perform CRUD operation
4. Close the connection
Declaring connectionStrings
Add the below connection string configuration in web.config file
<connectionStrings>
<add name="yourconnectinstringName" connectionString="Data
Source= DatabaseServerName; Integrated Security=true;Initial
Catalog= YourDatabaseName; uid=YourUserName;
Password=yourpassword; "
providerName="System.Data.SqlClient" />
</connectionStrings>
Example:
<connectionStrings>
<add name="EmployeeDbConn" connectionString="Data
Source=INBOOK_X1_SLIM\SQLEXPRESS;Initial
Catalog=EmploeeDb;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Establish the Connection
//Get connection string from web.config file
string strcon =
ConfigurationManager.ConnectionStrings["dbconnection"].Conne
ctionString;
con.Open();
PERFORM CRUD OPERATION
Executing the Commands
– Once connected to the database, you can execute
the set of commands that you're having and which
would execute on the server (or the data
provider) to execute the function you're trying
to do, such as a query for data, insert the
data, update records and so on and so forth.
});
}
Close the Connection
Close the connection object once the CRUD operations CRUD is
completed
conn.Close();
THANK YOU