1. I have a xml configuration file for my program which shown as below. I want to make my program to run at other machines. But for right now, I cant access defaultDatabase from code behind. Anyone can help???
2. Code Behind shown as below had error which is "dbSettings" cannot be declared as DatabaseSettings.
By the way, I had imports System.Data already.
Dim dbSettings As DatabaseSettings = CType(ConfigurationManager.GetSection("dataConfiguration"), DatabaseSettings) Dim defaultConnection As String = dbSettings.DefaultDatabase
Since you are using xml,the most advantage of xml is just to do most dynammic changes to the value of your connection string——So please diretly change that value in the xml file by using NotePad to open the xml file and do modifications……
If you still want to do changes to the web.config,you can just use XDocument(xml form)to analyze the file and do changes……
XDocument doc = XDocument.Load("xxx.xml");
XElement node = from item in doc.Descedants("connectionStrings").FirstOrDefault();
if(node!=null)
{
node.Attribute("connectionString").Valu=Your new value here;
doc.Save("your path & file name");
}
luckystar_20...
0 Points
14 Posts
How to Access defaultDatabase with dataConfiguration from Code Behind?
Jun 29, 2012 03:50 AM|LINK
1. I have a xml configuration file for my program which shown as below. I want to make my program to run at other machines. But for right now, I cant access defaultDatabase from code behind. Anyone can help???
Dim dbSettings As DatabaseSettings = CType(ConfigurationManager.GetSection("dataConfiguration"), DatabaseSettings)
Dim defaultConnection As String = dbSettings.DefaultDatabase
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings(defaultConnection).ToString()
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to Access defaultDatabase with dataConfiguration from Code Behind?
Jun 30, 2012 09:01 AM|LINK
Hi,
Since you are using xml,the most advantage of xml is just to do most dynammic changes to the value of your connection string——So please diretly change that value in the xml file by using NotePad to open the xml file and do modifications……
If you still want to do changes to the web.config,you can just use XDocument(xml form)to analyze the file and do changes……
XDocument doc = XDocument.Load("xxx.xml"); XElement node = from item in doc.Descedants("connectionStrings").FirstOrDefault(); if(node!=null) { node.Attribute("connectionString").Valu=Your new value here; doc.Save("your path & file name"); }