实际路径不正确 [英] realtive path not correct

查看:87
本文介绍了实际路径不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的winforms应用程序使用app.config文件,以便按如下方式存储连接字符串

i am using app.config file for my winforms application in order to store the connection strings as follows

<connectionStrings>
    <clear />
    <add name="Survey" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\Database\Master.mdb;Persist Security Info=True"

     providerName="System.Data.OleDb" />
    <add name="Model" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\Database\Model.mdb;Persist Security Info=True"

      providerName="System.Data.OleDb" />
</connectionStrings>
<appsettings>
    <add key="Database" value=".\\Database\" />
    <!--<add key="Database" value=".\Survey Designer DB 8-06-2012 latest\" />-->
    <add key="LoggerLevel" value="5" />

    <add key="ClientSettingsProvider.ServiceUri" value="" />
</appsettings>



当我在本地工作时它工作正常...但是当我从一个共享文件中选择一个文件时\\\172.16.2.5 \



路径。\\Database \ Master.mdb ins从本地文件系统获取文件,它将\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\在给定的路径.. ..抛出错误..无法找到指定的文件...



我正在使用。\\Database \ Master.mdb synatx so它仍然没有任何硬编码值。


It works fine when i am working local...but when i choose a file from a share like \\172.16.2.5\

the path .\\Database\Master.mdb instead of taking file from local file system it appends \\172.16.2.5\ to
.\\Database\Master.mdb and since Database\Master.mdb is not present in the given path..it throws error ..cannot find file specified ...

I am using .\\Database\Master.mdb synatx so it remains dynamice without any hardcoded values.

推荐答案

请参阅以下链接

http://www.connectionstrings.com/access [ ^ ]
Refer below link
http://www.connectionstrings.com/access[^]


Ok ..i解决了问题..问题是我使用的文件打开对话框,选项恢复目录为false所以它恰好在win中xp将工作目录更改为用户选择的文件对话框文件夹位置,以便在网络中搜索工作目录中的.//database工作文件夹..共享文件夹中不存在。





这只是面对win xp而不是win7





所以为了让它工作...我赢了xp我们必须将restoredefault目录设置为true..so它将目录带到root应用程序运行文件夹..







谢谢
Ok ..i fixed the problem .. the problem was that i was using a file open dialog box with the option restore directory as false so it happens that in win xp the working directory is changed to the file dialog folder location which user chooses so the .//database which is present in working directory is searched in network folder .. which is absent in shared folder .


this is only faced in win xp and not in win7


So in order to make it work ...i win xp we have to set restoredefault directory to true..so it brings the directory to the root application running folder..



Thanks


这篇关于实际路径不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆