Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何先更改与数据库的连接字符串_C#_Entity Framework_Connection String_Npgsql - Fatal编程技术网

C# 如何先更改与数据库的连接字符串

C# 如何先更改与数据库的连接字符串,c#,entity-framework,connection-string,npgsql,C#,Entity Framework,Connection String,Npgsql,我想更改数据库第一个项目中的数据源地址 这是我的代码: 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=Tru

我想更改数据库第一个项目中的数据源地址

这是我的代码:

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:'不支持关键字:'主机''


请不要添加不相关的标签。还请包括您收到的错误。System.ArgumentException:'关键字不受支持:'主机''。这是连接字符串的格式:Provider=PostgreSQL OLE DB Provider;数据源=myserver地址;位置=我的数据库;用户ID=我的用户名;密码=我的密码@Bibin无法使用您的codeSystem.ArgumentException:'关键字不受支持:'数据源''