Saturday, July 28, 2012

How to write the DataBase Connection String in Web.ConFig and How to Use that

File-> New->Website

Select the location and Click on Ok.

Now in web.config

 <connectionStrings>
    <add name="dbtaskallocation" connectionString="Data Source=localhost;database=taskallocation;user id=sa;password=uday" providerName="System.Data.SqlClient"/>
  </connectionStrings>


How to use this web.config.

page.cs

using System.Configuration;
using System.Data;
using System.Data.SqlClient;

SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["dbtaskallocation"].ToString());
        SqlCommand cmd=new SqlCommand("select * from tblemployee",con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        con.Open();
        DataSet ds=new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();

web.config





page.cs




Some important attributes for connection string

i Data Source: Specifies the data source name
ii. Server: The server name where the database resides
iii. Initial Catalog/Database: The database name if the data source supports more than one database
iv. User id/ uid: The user name for authentication
v. Password/ pwd: The corresponding password for authentication
vi. Pooling = true/false: Whether the connection should support pooling or not
vii. Min Connections: The minimum number of connections that should exist in the pool


viii. Max Connections: The maximum number of connections that can exist in the pool

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...