当我运行.exe时,它没有连接到数据库..... [英] when I ran the .exe it dosen't connect to database.......

查看:69
本文介绍了当我运行.exe时,它没有连接到数据库.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序已连接到Access 2007数据库,但是我使用inno setup编译器构建了安装程序,并将其安装在我的PC中,然后运行.exe,它没有连接到数据库. /> 但是当我以管理员身份运行它时,它可以正常工作...
我在PC上使用Windows7.
我该怎么做才能更正此问题.. ?? !!

my application is connected to access 2007 Database, but I built the setup by( inno setup compiler ) and install it in my pc ,then I ran the .exe and it dosen''t connect to the data base .
but when I ran it AS ADMINISTRATOR it work normally...
I work with windows 7 in my pc.
whate do I have to do to correct this..??!!

推荐答案

请参阅我对问题的评论.我们没有足够的信息来帮助您.

但是,您可以做几件事.首先,您需要在调试器下运行代码,并查看在哪里存在访问问题.您可以将执行与具有提升特权的执行进行比较.特别是,您可以使用System.Diagnostics.EventLog类将调试信息记录到系统日志中,请参见:
http://msdn.microsoft.com/en-us/library/system.diagnostics. eventlog.aspx [ ^ ].

或者,您可以比较两种情况,这些情况在调试器下以提升的特权运行所有程序.我的意思是,包括Visual Studio在内的所有内容.要以管理员身份运行,您可以使用以下选项:
http://www.sevenforums.com/tutorials/11841-run-administrator.html [ ^ ].

您发现与在Windows 7中使用某些非法目录路径名一样琐碎.这是问题的最典型来源之一.您应该排除使用任何硬编码的路径名.在任何情况下(无论是否与Windows 7一起使用)它都无济于事.您需要计算运行时可以使用的目录.

特别是,您可以使用System.Environment.GetFolderPath(System.Environment.SpecialFolder)获得特殊路径".请参阅:
http://msdn.microsoft.com/en-us/library/14tx8hby.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.environment. specialfolder.aspx [ ^ ].

—SA
Please see my comment to the question. We did not have enough information to help you.

However, you can do several things. First of all, you need to run code under debugger and see where you have an access problem. You can compare execution with the execution with elevated privileges. In particular, you can log debugging information in both to the system log using the class System.Diagnostics.EventLog, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

Alternatively, you can compare both cases running everything under debugger with elevated privileges. I mean, everything including Visual Studio. For running as administrator, you have the following options:
http://www.sevenforums.com/tutorials/11841-run-administrator.html[^].

You finding can be as trivial as using some directory path names illegal in Windows 7. This is one of the most typical sources of your problem. You should exclude use of any hard-coded path names. There are no cases when it can be useful (with Windows 7 or not). You need to calculate the directories you can work with during run time.

In particular, you can get the "special path" using System.Environment.GetFolderPath(System.Environment.SpecialFolder). Pleas see:
http://msdn.microsoft.com/en-us/library/14tx8hby.aspx[^],
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^].

—SA


在SA所说的顶部,如果您的数据库文件与.EXE位于同一文件夹中,则还有第二个问题.在Vista和7上,程序文件"下的所有内容对于普通用户都是只读的.这意味着您无法连接到此文件夹下的Access数据库,因为您需要对该文件所在的文件夹具有写权限才能使用它.

您必须将数据库文件移动到更合适的位置,例如CommonApplicationData文件夹下.使用Environment.GetFolderPath获取此枚举指向的文件夹路径.

http://msdn.microsoft.com/en-us/library/system.environment. specialfolder.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/14tx8hby (v = vs.85).aspx [
On top of what SA said, if your database file is in the same folder as your .EXE you have a second problem. On Vista and 7, everything under Program Files is readonly to normal users. This means you can''t connect to an Access database located under this folder because you need Write permissions to the folder the file is in to use it.

You''ll have to move your database file to a more suitable location, like under the CommonApplicationData folder. Use Environment.GetFolderPath to get the folder path that this enumeration points to.

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^]
http://msdn.microsoft.com/en-us/library/14tx8hby(v=vs.85).aspx[^]

Your setup is going to have to put the file in this folder path. There is usually a predefined variable in the setup tool that does this.


这篇关于当我运行.exe时,它没有连接到数据库.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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