.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Windows Application- app.config

Posted By: Jayakumar     Posted Date: March 01, 2010    Points:2   Category :Windows Application

how to declare connection string with app.config file in windows application(,net 3.5).

and how it use it with form.cs(c# coding).

i want a sqlserver table to be binded on button click event.

suggest me

Author: Amit Mehra             
Posted Date: March 01, 2010     Points: 5   


Its sample as asp.net application

1st add the reference of system.Configuration by right ass reference click on the project


to access the connection string value from app.config file in windows application

string conn = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"]

Please "Mark As Answer " if this post help you.
Author: Syed Shakeer Hussain             
Posted Date: March 01, 2010     Points: 5   

Hi JayaKumar,
A simple example of a configuration file would be the following:

<?xml version="1.0" encoding="utf-8" ?>
<add key="ConnectionString "
value="Server=localhost;Database=Northwind;Integrated Security=false;User Id=sa;Password=sa;" />

In .cs page read the connection string as follows:-

SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString "]);

Author: Lalij Mer             
Posted Date: March 01, 2010     Points: 5   

try this code

<add name="connString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|meradatabase.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

Please Check my answer if you help....
Thank You...

Author: Sagar Pardeshi             
Posted Date: March 02, 2010     Points: 5   

<?xml version="1.0" encoding="utf-8" ?>
<add name="SQLSERVER"
connectionString="Data Source=;Initial Catalog=;Integrated Security=True"
providerName="System.Data.SqlClient" />


strConnString = ConfigurationManager.ConnectionStrings["connectString"].ToString();

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend