Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.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# 如何在执行或安装时将visual studio中的文件路径修改到数据库 问题_C#_Sql_Database_Visual Studio_Ms Access - Fatal编程技术网

C# 如何在执行或安装时将visual studio中的文件路径修改到数据库 问题

C# 如何在执行或安装时将visual studio中的文件路径修改到数据库 问题,c#,sql,database,visual-studio,ms-access,C#,Sql,Database,Visual Studio,Ms Access,用visualstudio&C编写# 我已经完成了我的程序的编写,它连接到一个SQL数据库,这是目前工作得很好,但因为我想在其他计算机上部署这个程序,它抛出错误,由于不正确的文件路径。例如,在VisualStudio的设置部分,我得到了这个文件,它是我的数据库的文件路径 我试图更改的值的屏幕截图: 当我运行程序或将程序安装到计算机(一旦发布)时,是否有方法更改此值 谢谢你的帮助 谢谢 编辑:我曾考虑使用下面的代码来更改文件路径,但我只想更改此值一次。是否仍要执行此操作?(我尝试了此操作,但由于

用visualstudio&C编写#

我已经完成了我的程序的编写,它连接到一个SQL数据库,这是目前工作得很好,但因为我想在其他计算机上部署这个程序,它抛出错误,由于不正确的文件路径。例如,在VisualStudio的设置部分,我得到了这个文件,它是我的数据库的文件路径

我试图更改的值的屏幕截图:

当我运行程序或将程序安装到计算机(一旦发布)时,是否有方法更改此值

谢谢你的帮助

谢谢

编辑:我曾考虑使用下面的代码来更改文件路径,但我只想更改此值一次。是否仍要执行此操作?(我尝试了此操作,但由于它是只读的,因此可能无法工作)
Properties.Settings.Default.Value

Properties.Settings.Default.Save();
编辑2:尝试配置管理器,是否可以使用以下内容更改值:

ConfigurationManager.ConnectionStrings. 

设法解决了这个问题,谢谢你的建议

 //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[2].Value = con;
    }
}
//writing the connection string in config file
XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

如果有人感兴趣,可以使用OpenFileDialog。数据库现在可以正常加载。

您是否想过在安装过程中向用户询问路径?或者如果路径不存在,可以创建路径?我考虑过,但不确定我将如何进行此过程。正在试用新项目,立即安装项目。谢谢您的来信,[已解决],等等。我认为您没有足够的代表。我将在您的回复中添加一个wiki答案。
 //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[2].Value = con;
    }
}
//writing the connection string in config file
XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);