|
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:  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:  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:  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:  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:  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.
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|