Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a config file like this:-
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="CarrierConfig" value="C:\XTMS\XTMSService\XTMSConfig\CarrierConfig.xml"/>
<add key="MessagesFile" value="C:\XTMS\XTMSService\XTMSConfig\XTMSMessages.xml"/>
<add key="EmailConfig" value="C:\XTMS\XTMSService\XTMSConfig\EmailConfig.xml"/>
<add key="SmtpClient" value="mailhost.css.mc.xerox.com"/>
</appSettings>
<connectionStrings>
<add name="OracleConnectionold" connectionString="Data Source=ooosd;User ID=xkk1; Password=sda; Unicode=True" providerName="System.Data.OracleClient"/>
<add name="OracleConnection" connectionString="Data Source=ooop;User ID=dds; Password=fafa2009; Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
</configuration>
I am creating a batch file in which user will give the input.that input will decide which database will the application be connecting to.I want to Open this config file and edit the connection string.How can this be done??I am using windows XP

if you have Perl on Windows and can use it
my $config="file"; print "Enter Data Source: "; my $datasrc = <STDIN>;chomp($datasrc); print "Enter UserID: "; my $userid = <STDIN>;chomp($userid); print "Enter Unicode(True or False: "; my $unicode = <STDIN>;chomp($unicode); print "Enter password: "; my $pass = <STDIN>;chomp($pass); $string = "Data Source=".$datasrc.";User ID=".$userid."; Password=".$pass.";Unicode=".$unicode; while(<>){ chomp; if (/<add name=\"OracleConnection\"/ ){ s/connectionString="(.*?)\"/connectionString="$string"/; } print $_."\n"; }output:
# perl test.pl file Enter Data Source: new_data_source Enter UserID: new_user_id Enter Unicode(True or False: False Enter password: new_pass <?xml version="1.0"?> <configuration> <appSettings> <add key="CarrierConfig" value="C:\XTMS\XTMSService\XTMSConfig\CarrierConfig.xml"/> <add key="MessagesFile" value="C:\XTMS\XTMSService\XTMSConfig\XTMSMessages.xml"/> <add key="EmailConfig" value="C:\XTMS\XTMSService\XTMSConfig\EmailConfig.xml"/> <add key="SmtpClient" value="mailhost.css.mc.xerox.com"/> </appSettings> <connectionStrings> <add name="OracleConnectionold" connectionString="Data Source=ooosd;User ID=xkk1; Password=sda; Unicode=True" providerName="System.Data.OracleClient"/> <add name="OracleConnection" connectionString="Data Source=new_data_source;User ID=new_user_id; Password=new_pass;Unicode=False" providerName="System.Data.OracleClient"/> </connectionStrings> </configuration>

No I am trying to work on .Bat file which will be executed in command prompt.
I Also want some code that can replace
C:\ to D:\ if user enters D.
<add key="CarrierConfig" value="C:\XTMS\XTMSService\XTMSConfig\CarrierConfig.xml"/>
Thnx alot by the way for giving your time to it.

![]() |
How to read a file using ...
|
create a folder
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |