Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to read connection string from App.Config file.
As your solution I wrote this code

<configuration>
<connectionstrings>
<add name="CharityManagement">
connectionString="Data Source=.;Initial Catalog=CharityManagement;Integrated Security=True"/>


but I have no idea where shoud I give my database path in connection string and I want to use sqlserver in Local mode
can anybody help me out.
Thanks in Advance

What I have tried:


<configuration>
<connectionstrings>
<add name="con" connectionstring="Data Source=.;Initial Catalog=DB;Integrated Securiry=True">

Posted
Updated 3-Sep-16 17:24pm

In your app.config you would specify your connection string.

XML
<connectionStrings>
    <add name="DefaultConnection" connectionString="put your connection string here" providerName="System.Data.SqlClient" />
</connectionStrings>



In your c# code you can access it as such

C#
var connstring = ConfigurationManager.ConnectionStrings["DefaultConnection"];


Then from there you use connstring in whatever way you are accessing your database.
 
Share this answer
 
Comments
Karthik_Mahalingam 5-Sep-16 5:19am    
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