Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i m creating a simple application form with username , password, age and full name and i have created a table in db which is ms sql server. but i dont knw how to connect it in web config. plz help
Posted
Updated 12-Jun-17 20:00pm
Comments
bbirajdar 30-Apr-12 6:44am    
Reason for my vote of 1
Homework
Prasad_Kulkarni 3-May-12 1:25am    
Glad it helps!
Thank You for 'Accepting Solution' :)

ConnectionStrings section in web.config.

Sql Authentication
XML
<connectionStrings>
  <add name="ConnectDBString" connectionString="server=SqlServerName;database=DatabaseName;uid=User;password=Password;" />
</connectionStrings>


To read the connection string into your code, use the ConfigurationSettings class.

string connStr = ConfigurationManager.ConnectionStrings["ConnectDBString"].ConnectionString;



For further information please go through the following links
1) ConnectionStrings
2) ConnectionStrings

Check this answer for reference:
How to make database connectivity in asp.net[^]
 
Share this answer
 
v3
This will be Helpful to u.

First use the Namespaces

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

C#
public partial class Default : System.Web.UI.Page
{
    private static readonly string _connString = String.Empty;
    SqlConnection con = new SqlConnection(_connString);



C#
static Default()
    {
  _connString = WebConfigurationManager.ConnectionStrings["DataBaseNameConnectionString"].ConnectionString;
    }

}


and this code in WEB.Config File

XML
<connectionStrings>
  <add name="DataBaseNameConnectionString" connectionString="Data Source=system name or Server name;Initial Catalog=DataBaseName;user id=sa;password=123" providerName="System.Data.SqlClient"" />
</connectionStrings>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900