Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
3.71/5 (3 votes)
See more:
hello, i am developing a web application for document management system. here my requirement is i want to save data at two sql servers at different location among which
1)first sql server is my localhost
2)second sql server is the one where i have hosted my website.
i want to save data simultaneously at both the servers. pls tell me how can i achieve this & give me easiest solution .
Posted

Define two ConnectionStrings in web.config file, one for localhost and other for that external database.

Now, while doing database operations, just initialize the SqlConnection class with localhost first and execute the required command. Then initialize the same SqlConnection class or another with the external database ConnectionString and execute the command.
 
Share this answer
 
Comments
Sumit_Pathak 4-Jan-14 2:09am    
<connectionstrings>
<add name="conn" connectionstring="Data Source=PC;Initial Catalog=demo1;User ID=sa;Password=itpaper">
<add name="conn_2" connectionstring="Data Source=PC;Initial Catalog=demo2;User ID=sa;Password=***">


<connectionstrings>
<add name="conn" connectionstring="Data Source=PC;Initial Catalog=demo1;User ID=sa;Password=****">


if i add these both connection string in web.config then i m getting this below error
Error 2 Sections must only appear once per config file. See the help topic <location> for exceptions. C:\Documents and Settings\User\My Documents\Visual Studio 2008\WebSites\WebSite20\Web.config 32
<connectionstrings>
<add name="conn" connectionstring="Data Source=PC;Initial Catalog=demo1;User ID=sa;Password=itpaper"></add>
<add name="conn_2" connectionstring="Data Source=PC;Initial Catalog=demo2;User ID=sa;Password=***"></add>
<add name="conn_3" connectionstring="Data Source=PC;Initial Catalog=demo1;User ID=sa;Password=****"></add>
</connectionstrings>

<connectionstrings>
<add name="conn" connectionstring="Data Source=PC;Initial Catalog=demo1;User ID=sa;Password=****">

</connectionstrings>

You should not add another ConnectionString tag, instead add new ConnectionString inside the existing tags.
According to the error, it says you can't have same tags many times.

So, correct it. It will work then.
 
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