Как изменить строку соединения с базой данных в первую очередь - PullRequest
0 голосов
/ 30 января 2020

Я хочу изменить адрес источника данных в моем первом проекте базы данных.

Это мой код:

string connect = "metadata=res://*/ornekDBEnt.csdl|res://*/ornekDBEnt.ssdl|res://*/ornekEnt.msl;provider=Npgsql;provider connection string="Host=127.0.0.1;Username=postgres;Password=pass1;Persist Security Info=True;Database=ornekdb"";
updateConfigFile(connect);

public void updateConfigFile(string con)
{
    //updating config file
    XmlDocument XmlDoc = new XmlDocument();
    //Loading the Config file
    XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

    foreach (XmlElement xElement in XmlDoc.DocumentElement)
    {
        if (xElement.Name == "connectionStrings")
        {
            //setting the coonection string
            xElement.FirstChild.Attributes[1].Value = con;
        }
    }
    //writing the connection string in config file
    XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
} 

Я получаю следующую ошибку

System.ArgumentException: 'Ключевое слово не поддерживается:' хост '.'

...