Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi all,

in one of my project we have a need to change database connection dynamically. website is build using asp.net mvc 4 and entity framework. currently we create entity framework class by adding it from add new item and apply the connection string from wizard only. now what we need is admin can change server settings and that will be saved in one of the xml file in the root directory. we need to concatenate the server details and apply a new connection string to entity framework class.

can someone please give me idea.
Posted
Comments
Maciej Los 27-Feb-14 15:28pm    
What's the problem?
ravikhoda 27-Feb-14 22:38pm    
problem is that now my connection string is not fixed and we need to change datasource initial catalog based on xml file which is separate from Web config file. how to update web config file connection string based on that xml file.
Maciej Los 28-Feb-14 1:53am    
That is no problem. See updated answer ;)

1 solution

I have no idea what kind of issue do you have... You did provide enough information about your needs. Now, you need to start coding. That's all.

Please see: Connection Strings and Configuration Files[^]. It might help you.

[EDIT]
Quote:
problem is that now my connection string is not fixed and we need to change datasource initial catalog based on xml file which is separate from Web config file. how to update web config file connection string based on that xml file.


The simplest way i can imagine is:
1) create[^] DataTable[^] object
2) add columns[^] and rows[^] (data)
3) save DataTable data to Xml file[^]
That's all! ;)

Tip: to get data from xml, use DataTable,ReadXml method[^]

There is many other ways to achieve that, for example using XML DOM document, XMLWriter, etc.

[/EDIT]
 
Share this answer
 
v2

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