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


Top 5 Contributors of the Month
david stephan

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
hi

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

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

Hi,

Its sample as asp.net application

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

Than

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

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


Thanks,
Amit
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" ?>
<configuration>
<appSettings>
<add key="ConnectionString "
value="Server=localhost;Database=Northwind;Integrated Security=false;User Id=sa;Password=sa;" />
</appSettings>
</configuration>

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...

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

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

</configuration>


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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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