与数据库进行安装ms访问数据库但访问被拒绝错误 [英] make setup along with database ms Access database but Access Denied Error
问题描述
先生,我制作一个桌面应用程序,后端使用Access数据库,之后我为客户端使用进行设置并在Aaplication文件夹中注册数据库文件。之后,我将我的数据库文件移动到另一个文件夹..因为它让我错误更新查询像这样...所以先生我使用此代码删除删除此错误
sir ,, i make a desktop application and back end ussing Ms Access Database After that i make a setup for client uses and attech a Database file inside Aaplication folder. after that i move my database file to another folder .. because it get me error updatable Query like that ... so sir i use this code to remove remove this error
string targetPath = Application.UserAppDataPath + "\\Database";
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
string Source = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Release\\", "");
string sourceFile = Source + "Database\\InventoryNewDatabase.mdb";
string destinationFile = Application.UserAppDataPath + "\\Database\\InventoryNewDatabase.mdb";
// To move a file or folder to a new location:
try{
System.IO.File.Move(sourceFile, destinationFile);
}
catch(Exception Er)
{
MessageBox.Show("Database File Does Not found\n Please Contect Your Application Provider \n Thank You"+ Er.ToString(),"Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
然后我出现此错误:
在Dialogbox中。显示此错误:---
System.UnauthorizedAccessException:拒绝访问路径。
在System.IO._Error.WinIOError(It32 errorCode,String maybeFullPath)
at System.IO._Error.WinIOError()
at System.IO.File.Move (String sourceFileFileName,String destFileName)
在Inventoryproject.Program.Main()
如何解决这个问题先生我想和数据库文件一起设置..所以请帮帮我
先谢谢你..
then i Getting This Error :
In The Dialogbox.Show this Error:---
System.UnauthorizedAccessException: Access to the path is denied.
at System.IO._Error.WinIOError(It32 errorCode,String maybeFullPath)
at System.IO._Error.WinIOError()
at System.IO.File.Move(String sourceFileFileName,String destFileName)
at Inventoryproject.Program.Main()
how to over come this problem sir I want to make a setup along with Database file .. so please Help me
Thanks in Advance ..
推荐答案
您正确地发现程序文件夹不是数据库文件的好地方,但它属于当前用户或所有用户可访问的文件夹。
但您没有看到的一点是,在用户帐户下运行的应用程序不得删除t他是程序文件夹中的数据库文件(System.IO.File.Move包含删除操作!)。
正确的解决方案是更改安装例程:它必须将数据库文件放入正确的位置文件夹已经。
You correctly found out that the program folder is not a good place for the database file, but that it belongs into a folder accessible for the current user or all users.
But the point you did not see is that your application running under a user account must not delete the database file from the program folder either (System.IO.File.Move includes a delete operation!).
The correct solution is to change your setup routine: it must place the database file into the correct folder already.
这篇关于与数据库进行安装ms访问数据库但访问被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!