Click here to Skip to main content
15,904,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am enhancing a project, in that web.config

XML
<connectionstrings>
              <remove name="LocalSqlServer" />
    </connectionstrings>


I need to specify the database name where I have to specify?

Please hep me.

Regards
Praveen
Posted
Updated 15-Sep-11 19:31pm
v3

1 solution

You can define like this
XML
<connectionStrings>    
    <add name="connstr"  providerName="System.Data.SqlClient" connectionString="Data Source=Servername;Initial Catalog=DBName;Integrated Security=True"/>
  </connectionStrings>

Accessing in C#:
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ToString();

Or
<appSettings>
        <add key="constr" value="Data Source=ServerName;Initial Catalog=DBName;User ID=sa;Password=123456"/>    
  </appSettings>

Accessing in C#:

string connStr = System.Configuration.ConfigurationManager.AppSettings["constr"].ToString();



appSettings is meant for any data string that can be stored while connectionString is meant for storing the database connection strings only.
 
Share this answer
 
v2
Comments
rkthiyagarajan 16-Sep-11 1:02am    
Ya i used Its Work.
m@dhu 16-Sep-11 1:32am    
My 5!

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