Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

I am working in a Window Application but my need is application read database connection from text file . That is working but I want when I publish my Application its also Publish txt file in same folder. Thats why when ever need to change in connection string its by txt file.

ANd When Install this exe then also txt file will be save in local user system.
Posted
Updated 15-Apr-13 0:42am
v2
Comments
[no name] 15-Apr-13 6:37am    
Can you specify your problem again?
Neetesh Agarwal 15-Apr-13 6:42am    
My Problem is When client Install my publish Application then There should also be text file.

First of all, be sure to have a proper connection string to your MySQL database (http://connectionstrings.com/mysql[^]).

Forget the text file. More precisely forget your interpretation of a text file, since .NET has the solution out of the box. It is called app.config, and that one has a section just for connection strings. Check here: How to get Connection String from App.Config in c#[^]. You migth find these also useful: Configuring a Connection String in the App.Config File During Runtime in C#[^], http://msdn.microsoft.com/en-us/library/ms171887.aspx[^]

Please note, that the app.config (an XML) is automatically built, and if you include it in your install kit, it is also deployed.

You can even secure the connection strings. Check here: http://msdn.microsoft.com/en-us/library/89211k9b(v=vs.80).aspx[^]
 
Share this answer
 
v2
Comments
Neetesh Agarwal 15-Apr-13 7:22am    
ALl thing are working . My need is to create set up with text file and When I Install so there should be that txt file also available.
Zoltán Zörgő 15-Apr-13 7:23am    
Than your post is not good, since you need to make an installer - that's all. Look here: http://support.microsoft.com/kb/307353
Neetesh Agarwal 15-Apr-13 8:04am    
Thanks..... Now done
Hi,

Try This

In that Text file Just put Online DB Name Not Path

Ex:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source= #FilePath# \DB_New.mdb


in code

Read Connstring from txt File and replace

string constring = "";//Read From txt File
string path = Application.ExecutablePath;
string resultPath = path.Substring(0, path.LastIndexOf("\\"));

constring.replace("#FilePath#",resultpath);


Note : It will workout if Your DB Location reside in the same folder of publish EXE File

Thanks

Siva Rm K
 
Share this answer
 
Comments
Zoltán Zörgő 15-Apr-13 7:12am    
MDB??? What has this to do with MySQL?
Neetesh Agarwal 15-Apr-13 7:13am    
hello Zoltán Zörgő ,

If u know solution please reply
Thanks
Zoltán Zörgő 15-Apr-13 7:17am    
See my answer.
rmksiva 15-Apr-13 8:18am    
Thank

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