使用 ODBC 从位于 Program Files 文件夹中的数据库读取
我们有一个应用程序,将其数据库文件存储在 Program Files 目录的子文件夹中。这些文件被重定向到 Vista 和 Windows 7 中的 VirtualStore。我们使用 Microsoft DataReports (VB6) 表示数据库中的数据。到目前为止,一切都很好。
但我们现在想要使用 Crystal Reports XI 来表示数据库中的数据。我们的想法是不将这些数据从我们的程序传递给 CR,而是让 CR 通过 ODBC 使用系统 DSN 从数据库中检索它。通过这种方式,我们希望为用户提供更灵活的设计自己的报告的能力。但我们确实想要确保的是,当用户安装我们的程序或程序调用 Crystal Report 时,这些系统 DSN 已正确配置。
例如,是否有一种聪明的方法可以使用系统变量来执行此操作,而不必编写检查操作系统版本、操作系统上是否启用了 UAC、是否已取消对 Program Files 文件夹的写入限制等的例程然后调整系统 DSN 以指向 C:\Program Files\OurApp\Data 文件夹或 C:\Users\User\AppData\VirtualStore\Program Files\OurApp\Data 文件夹?
也欢迎提出完全不同方法的建议!
We have an application that stores its database files in a subfolder of the Program Files directory. These files are redirected to the VirtualStore in Vista and Windows 7. We represent data from the database using Microsoft DataReports (VB6). So far so good.
But we now want to use Crystal Reports XI to represent data from the database. Our idea is to NOT pass this data to CR from our program, but to have CR retreive it from the database using a a system DSN through ODBC. In this way we hope to present our users with more flexibility in designing their own reports. What we do want to ensure though is that these system DSNs are configured correctly when the user installs our program or when the program calls the Crystal Report.
Is there a smart way to do this using System variables for instance, instead of having to write a routine that checks for OS-version, whether UAC is enabled on the OS, whether the write restrictions on the Program Files folder have been lifted, etc and then adapts he System DSN to point to either the C:\Program Files\OurApp\Data folder, or the C:\Users\User\AppData\VirtualStore\Program Files\OurApp\Data folder?
Suggestions for an entirely different approach are welcome too!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
新应用程序应该有一个指定requestedExecutionLevel 的应用程序清单。这将声明您的程序“支持 Vista”并绕过虚拟化尝试。
在安装过程中,您应该创建一个类似 [CommonAppData]\Company\App\Full 的文件夹,并设置该文件夹的安全性以允许每个人(或用户)完全访问。将您的数据库放入此文件夹中。
对于 MDB,您可以在此处删除数据库。对于客户端/服务器数据库,放置 UDL 文件 这里。另请参阅使用通用数据链接 (.udl) 文件。
ODBC 和 DSN 是相当过时的技术。
使用建议的方法应该适用于几乎所有计算机,但最旧的 Win95 计算机除外。
New applications should have an application manifest that specifies requestedExecutionLevel. This declares your program "Vista aware" and bypasses attempts at virtualization.
During installation you should create a folder like [CommonAppData]\Company\App\Full and set security on this folder to allow Full Access by Everyone (or by Users). Put your database into this folder.
For an MDB you can drop the database right here. For a client/server database put a UDL file here. Also see Use Universal Data Link (.udl) Files.
ODBC and DSNs are pretty obsolete technologies.
Using the suggested approaches should work for almost anything but the oldest Win95 computer.
这是 Access 数据库吗?你没有具体说明。
对于 Access 数据库,安装时无需将 DSN 指向特定数据库。您可以修改连接字符串以在运行时指向不同的数据库(详细信息)。例如,
您能否在运行时简单地读取安装路径(在 VB6 中为
App.Path
),然后向 Crystal Reports 发送不同的连接字符串?Is this an Access database? You haven't specified.
For an Access database, you don't need to point your DSN to a specific database when you install it. You can modify the connection string to point to different databases at runtime (details). For instance
Can you simply read the installation path at runtime (in VB6 it is
App.Path
) and then send a different connection string to Crystal Reports?看起来虚拟存储会处理所有事情,因此即使数据库已重新定位到虚拟存储,您也可以将 DSN 公然指向 C:\Program Files\MyApp\Data\mydb.mdb。
It seems that Virtual Store takes care of everything, so you can point the DSN blatantly at C:\Program Files\MyApp\Data\mydb.mdb even while the database has been relocated to the Virtual Store.
当前版本
您可能想要检测系统正在运行的Windows 当前版本。
这反过来将帮助您确定正确的路径。
如何查找 Windows 版本、内部版本和修订号?
阅读注册表项 –
CurrentBuildNumber 是您的 Windows 内部版本号。然后 CurrentVersion 值是您的 Windows 版本,即 Windows 7、Windows Vista、Windows XP 等的版本。 EditionID 和 ProductId 可以了解 Windows 版本和产品 ID。
例如,在值
6001.17387.x86fre.vistasp1_gdr.070927-1921
中:前四位数字代表内部版本号,即 6001,
接下来的五位数字代表 Windows 版本号,即 17387。
x86 告诉您正在运行 32 位操作系统。
祝你好运!
Current Version
You might want to detect the current-version of Windows the system is running.
This will in turn help You in determining the correct PATH.
How to find windows version, build and revision numbers??
Read the the Registry keys –
The CurrentBuildNumber is your Windows Build Number. Then CurrentVersion value is your windows version i.e. the version of your windows 7, windows vista, windows xp, etc. EditionID and ProductId to know the windows-edition and product-id.
For example, in the value
6001.17387.x86fre.vistasp1_gdr.070927-1921
:the first four digits stand for build number i.e. 6001 and
the next five digits stand for windows revision number i.e. 17387.
x86 tells you that you are running a 32-bit operating system.
GoodLUCK!!