dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Memberstarunkumar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » .NET »

Call the connection string from App.config for Windows Application


Posted Date: 20 Aug 2012      Posted By:: Gopi A     Member Level: Silver    Member Rank: 350     Points: 5   Responses: 5



Hi,

I cannot able to call the connectionstring from app.config file. I am using visualstudio 2010. Below is my code.

<configuration>

<connectionStrings>

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

</connectionStrings>

</configuration>


How can i use this connection in windows application in form load event.

Please help me.

Regards,
Gopi A

-----------------------------------------------------------------------------
Regards,
Gopi A.
+91 9894315571
Skype:gopi.net




Responses

#684764    Author: RayalaHariKishore      Member Level: Gold      Member Rank: 51     Date: 20/Aug/2012   Rating: 2 out of 52 out of 5     Points: 2

hi,
first include system.configuration and then use this stmt
string value = ConfigurationSettings.AppSettings["test"].ToString();

Rayala HariKishore

try..try..try...you achieved it.
http://rayalaharikishore.wordpress.com/



 
#684769    Author: saravanakumar      Member Level: Gold      Member Rank: 195     Date: 20/Aug/2012   Rating: 2 out of 52 out of 5     Points: 3

try this,
string value = ConfigurationManager.ConnectionStrings["MMConnectionString"].ConnectionString;

if it is sqlserver database means use this,
 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MMConnectionString"].ConnectionString);


if it is access database means use this,
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["MMConnectionString"].ConnectionString);[/c


 
#684818    Author: Paritosh Mohapatra      Member Level: Diamond      Member Rank: 6     Date: 20/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

You can store the Connection String in App.Config file.

Please follow these steps:

1) Right Click on the Windows Application -> Add -> New Item... -> Select Application Configuration File -> Ok

2) In the newly add App.Config file, add the following entry within configuration element:


<appSettings>
<add key="sqlcon" value="server=.;integrated security=true;database=databasename;"/>
</appSettings>


3) In the form you can use the following code to read the Connection String:


string ConnectionString = ConfigurationSettings.AppSettings["sqlcon"].ToString();



Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM






 
#684828    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 20/Aug/2012   Rating: 2 out of 52 out of 5     Points: 2

hi,

right click on your project name in solution explorer and then choose System.Configuration as reference. then you can get connection string like below line


OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["myconnection"].ToString());


Regards
N.Ravindran
Your Hard work never fails



 
#684843    Author: Gopi A      Member Level: Silver      Member Rank: 350     Date: 20/Aug/2012   Rating: 2 out of 52 out of 5     Points: 1

Hi All,

Thanks for your help.

-----------------------------------------------------------------------------
Regards,
Gopi A.
+91 9894315571
Skype:gopi.net



 
Post Reply
You must Sign In to post a response.

Next : Datagridview chekbox click event
Previous : Dataset to Crystal Report....
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.