Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi!!
how i can to read a coonection string from FILE on c#
i Using aps.net mvc4...


thnks!!!
Posted
Comments
Rahul Rajat Singh 4-May-12 6:57am    
what kind of file you are using XMl or plain text.

I assume you have it stored in you Web.Config file. If that is the case, here is the solution:

http://msdn.microsoft.com/en-us/library/ms178411.aspx[^]
 
Share this answer
 
hi,
First you should keep your connectionstring in the web.config file of your application
and get the connectionstring in your code like this:

C#
string connStr=ConfigurationManager.ConnectionStrings["myConnection"].ToString();

here myConnection is the name of ConnectionString in web.config file.

and if you store the connection string in any other file on your system then get it like

C#
string connStr = File.ReadAllText("myFile.txt");

but the second one is not a good way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900