ADO.NET Connection

The Ado.net connection object is provide to database connectivity i.e application to Data Source. the entry point to a database .

Important Point :

When the connection of an object is instantiated connection between the DB (Sqlserver). in connection string that contains the information about the database server name, server type, database name, connection type, and database user credentials. Once the connection string is passed and the connection object is created, you can establish a connection with the database. A connection string is usually stored in the web.config file or app.config file of an application.


Connection to an ADO.NET Database in web-config.


<connectionStrings>
                     <add name="DBConn" connectionString="Data Source= ChandanSERVER\chandanSERVER;Initial Catalog= EmployeeRegister;
User ID=sa,pwd=sa123" providerName="System.Data.SqlClient"/>  
</connectionStrings>


if some one not add user Id and password ?

<connectionStrings>
<add name="DBConn" connectionString="Data                              Source=.\SQLEXPRESS;Initial Catalog=EmployeeRegister;
 Integrated Security=True;Pooling=False"/>
</connectionStrings>
 

Or you can use this in your app.config or web.config.


<connectionStrings>
  <add name="DBConn"  connectionString="data source=.;

 database=Sample_Test_DB; Integrated Security=SSPI"
        providerName="System.Data.SqlClient" />
</connectionStrings>


The "data source" is the IP Address of the SQL Server that we want to connect to. If you are working with a local machine of sql server, you can just specify DOT(.) or find out your sql server ip address. If the server is on a network, then use Name or IP address and user id and password..


How to read the connection string from web.config file?


private void connection()

{
string constring = ConfigurationManager.ConnectionStrings["DBConn"].ToString();
con = new SqlConnection(constring);
}

Different .NET Data Providers

Data Provider for SQL Server - System.Data.SqlClient

Data Provider for Oracle - System.Data.OracleClient
Data Provider for OLEDB - System.Data.OleDb
Data Provider for ODBC - System.Data.Odbc