我有这个问题,在我的程序中我动态设置服务器地址并尝试连接到我的数据库,如果我提供的地址正确,它可以正常工作,如果不正确,则无法连接,这是正常的。之后我想更改此地址,但即使我在代码中更改它并尝试再次连接我的数据库,它仍然会记住旧配置并且仍然无法连接。我应该怎么做才能改变它?
我这样设置我的配置:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
foreach (XmlElement element in xmlDoc.DocumentElement)
{
if (element.Name.Equals("ideablade.configuration"))
{
foreach (XmlNode ele in element.ChildNodes)
{
if (ele.Name == "objectServer")
{
var node = ele;
node.Attributes["remoteBaseURL"].Value = remoteBaseURL;
node.Attributes["serverPort"].Value = serverPort;
node.Attributes["serviceName"].Value = serviceName;
}
}
}
}
xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
ConfigurationManager.RefreshSection("ideablade.configuration");
我尝试像这样连接到我的数据库
if (BeczkaModel!= null)
{
BeczkaModel.Disconnect();
BeczkaModel= null;
}
IdeaBladeConfig.Instance.ObjectServer.RemoteBaseUrl = remoteBaseURL;
IdeaBladeConfig.Instance.ObjectServer.ServerPort = (int)double.Parse(serverPort);
IdeaBladeConfig.Instance.ObjectServer.ServiceName = serviceName;
IdeaBladeConfig.Instance.ObjectServer.ClientSettings.IsDistributed=true;
BeczkaModel= new BeczkaContainer();
BeczkaModel.AuthorizedThreadId = null;
BeczkaModel.Connect();