What is the architecture of connected environment of data access in ADO.Net?
The connected environment of data access is the traditional procedure for accessing data programmatically. The differentiating property of the connected data access environment is that here you (the programmer) is required to manage the connection with the database. You can only perform database operations when, there exists an open connection to the database.
Hence, before performing any database operation (select, update, insert, delete), the programmer opens a database connection and close the database connection after performing the database operations.
The important objects for working in the connected environment are:
• Connection (SqlConnection, OleDbConnection, etc): It represents a connection to the database. All the connection objects in the ADO.Net implement the System.Data.IDbConnection interface.
• Command (SqlCommand, OleDbCommand, etc): It represents the SQL command sent to the database, e.g., SELECT, UPDATE, INSERT, DELETE. All commands in ADO.Net implements IDbCommand interface .
• DataReader (SqlDataReader, OleDbDataReader, etc): It represents a data stream that can be used to read the result of your query returned by the database server. Using this object, you read the individual records and their fields returned as a result of your query to the database server. All the data readers in ADO.Net implement the System.Data.IDataReader interface.
How do I read data (or records) from database using data reader?
To read data from the database, you first make a connection object (SqlConnection, etc) and open it.
How do I insert records using data reader?
The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().
How do I update records using data reader?
The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().
How do I delete records using data reader?
The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().
How do I write common code for different dot net framework data providers?
The System.Data namespace contains the interfaces implemented by different dot net framework data providers, such as:
• IDbConnection implemented by SqlConnection, OracleConnection, OleDbConnection, OdbcConnection classes represents a connection with the database server
• IDbCommand implemented by SqlCommand, OracleCommand, OleDbCommand, OdbcCommand classes represents an SQL command passed to the database server
• IDbDataAdapter implemented by SqlDataAdapter, OracleDataAdapter, OleDbDataAdapter, OdbcDataAdapter classes represents a data adapter used to fill the data set in the disconnected environment of the ADO.Net
• IDataReader implemented by SqlDataReader, OracleDataReader, OleDbDataReader, OdbcDataReader classes represents a data reader used to read records from the database server, analogous to read only, forward only cursor
• IDbTransaction implemented by SqlTransaction, OracleTransaction, OleDbTransaction, OdbcTransaction classes represents a transaction established with the database server
What is a stored procedure?
A stored procedure is a precompiled executable object that contains one or more SQL statements. A stored procedure may be written to accept inputs and return output.
What is the advantage of using stored procedure over the SQL queries?
Writing the SQL statements inside our code is usually not a good idea. In this way you expose your database schema (design) in the code which may be changed. Hence most of the time programmers use stored procedures instead of plain SQL statements.
A stored procedure is a precompiled executable object that contains one or more SQL statements. Hence you can replace your complex SQL statements with a single stored procedure. Since, stored procedures are precompiled objects they execute faster at the database server.
Most of the time, stored procedures contain more than one command; in this case, the time to pass the individual commands to the database server from the program is saved. The database is issued just one command (to execute the stored procedure) and the DB server executes all the commands and returns the result in the end. Hence, the overall interaction time with the DB server reduces in a great deal.
This can result in a huge optimization in case where the DB server is accessed via a slow network.
RELATED POST
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART THREE
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FOUR
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FIVE
ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE
ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO
You can also learn the concept of frame work concept in detail with questions and answers in the following place.
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART ONE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TWO
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART THREE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FOUR
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FIVE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SIX
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SEVEN
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART EIGHT
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART NINE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TEN
The connected environment of data access is the traditional procedure for accessing data programmatically. The differentiating property of the connected data access environment is that here you (the programmer) is required to manage the connection with the database. You can only perform database operations when, there exists an open connection to the database.
Hence, before performing any database operation (select, update, insert, delete), the programmer opens a database connection and close the database connection after performing the database operations.
The important objects for working in the connected environment are:
• Connection (SqlConnection, OleDbConnection, etc): It represents a connection to the database. All the connection objects in the ADO.Net implement the System.Data.IDbConnection interface.
• Command (SqlCommand, OleDbCommand, etc): It represents the SQL command sent to the database, e.g., SELECT, UPDATE, INSERT, DELETE. All commands in ADO.Net implements IDbCommand interface .
• DataReader (SqlDataReader, OleDbDataReader, etc): It represents a data stream that can be used to read the result of your query returned by the database server. Using this object, you read the individual records and their fields returned as a result of your query to the database server. All the data readers in ADO.Net implement the System.Data.IDataReader interface.
How do I read data (or records) from database using data reader?
To read data from the database, you first make a connection object (SqlConnection, etc) and open it.
How do I insert records using data reader?
The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().
How do I update records using data reader?
The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().
How do I delete records using data reader?
The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().
How do I write common code for different dot net framework data providers?
The System.Data namespace contains the interfaces implemented by different dot net framework data providers, such as:
• IDbConnection implemented by SqlConnection, OracleConnection, OleDbConnection, OdbcConnection classes represents a connection with the database server
• IDbCommand implemented by SqlCommand, OracleCommand, OleDbCommand, OdbcCommand classes represents an SQL command passed to the database server
• IDbDataAdapter implemented by SqlDataAdapter, OracleDataAdapter, OleDbDataAdapter, OdbcDataAdapter classes represents a data adapter used to fill the data set in the disconnected environment of the ADO.Net
• IDataReader implemented by SqlDataReader, OracleDataReader, OleDbDataReader, OdbcDataReader classes represents a data reader used to read records from the database server, analogous to read only, forward only cursor
• IDbTransaction implemented by SqlTransaction, OracleTransaction, OleDbTransaction, OdbcTransaction classes represents a transaction established with the database server
What is a stored procedure?
A stored procedure is a precompiled executable object that contains one or more SQL statements. A stored procedure may be written to accept inputs and return output.
What is the advantage of using stored procedure over the SQL queries?
Writing the SQL statements inside our code is usually not a good idea. In this way you expose your database schema (design) in the code which may be changed. Hence most of the time programmers use stored procedures instead of plain SQL statements.
A stored procedure is a precompiled executable object that contains one or more SQL statements. Hence you can replace your complex SQL statements with a single stored procedure. Since, stored procedures are precompiled objects they execute faster at the database server.
Most of the time, stored procedures contain more than one command; in this case, the time to pass the individual commands to the database server from the program is saved. The database is issued just one command (to execute the stored procedure) and the DB server executes all the commands and returns the result in the end. Hence, the overall interaction time with the DB server reduces in a great deal.
This can result in a huge optimization in case where the DB server is accessed via a slow network.
RELATED POST
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART THREE
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FOUR
ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FIVE
ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE
ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO
You can also learn the concept of frame work concept in detail with questions and answers in the following place.
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART ONE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TWO
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART THREE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FOUR
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FIVE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SIX
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SEVEN
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART EIGHT
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART NINE
MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TEN
No comments:
Post a Comment