.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 >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Connection string in app.config?

Posted By: Sameer     Posted Date: April 09, 2010    Points:2   Category :C#
How to write a connection string in app.config in c# windows application using ms-access db?

Please if possible give some example?

Responses
Author: Venkat             
Posted Date: April 09, 2010     Points: 5   

HI,

To store the connection string in app.config file you can use Connectionstring tag in app.config

 <connectionStrings>
<add name="Name"
connectionString="Valid Connection String;" />
</connectionStrings>



Now to retrieve the connection value from code you can use this example

string myConnectionString = ConfigurationManager.ConnectionStrings["Name"].ConnectionString;


Mark As Answer if this solve your problem
Warm Regards,
Venkat
Author: Nikhil Kumar             
Posted Date: April 09, 2010     Points: 5   

Use this link to get a perfect example... with detail that how to use this in .aspx page also

http://dotnetask.blog.co.in/category/defining-connectionstring-in-webconfig-and-using-in-aspx-page/

and leave your one precious comment...

Thanks

Be helpful and enjoy life because it comes only onces. Give all the happiness to yours and remember it doesn't comes by money ...
Author: Sameer             
Posted Date: April 10, 2010     Points: 5   

Thanks,

I have to give the user defined name for the connection string, or the connection string which is available?

Author: Nikhil Kumar             
Posted Date: April 10, 2010     Points: 5   

yes you can give the name which you like in place of "name" simple :)

Be helpful and enjoy life because it comes only onces. Give all the happiness to yours and remember it doesn't comes by money ...
Author: Sagar Pardeshi             
Posted Date: April 10, 2010     Points: 5   

hi
< ?xml version="1.0" encoding="utf-8" ?>
< configuration>
< appSettings>
< add key="ConnectionString"
value="data source=localhost;
initial catalog=FinAccounting;
Integrated Security=true;"/>
< /appSettings>


Imports System

Imports System.IO

Imports System.Configuration

Module FileCleanup

Dim FileName As String

Dim FilePath As String = ConfigurationManager.AppSettings("ConnectionString")


Author: Sameer             
Posted Date: April 12, 2010     Points: 5   

Thanks sagar,
Its not working. As the dll file Configuration manager is not coming in my project.

Author: Alankar             
Posted Date: June 06, 2016     Points: 20   

Sameer,

Add System.Configuration Dll in your consuming project.





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