如何使用应用程序复制访问数据库文件? [英] How do I copy an access database file with my application?

查看:98
本文介绍了如何使用应用程序复制访问数据库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Visual Basic应用程序中,我有一个正在使用的访问数据库文件.它显示在解决方案资源管理器窗口中.在我安装之前,一切正常.由于某种原因,数据库文件不随安装一起提供.我想我需要在运行时编辑连接字符串,但是我不确定.我以前没有做过类似的事情,也找不到有关它的信息.

In my Visual Basic Application, I have an access database file that I am using. It shows up in the solution explorer window. Everything works great until I install. The database file doesn't go with the installation for some reason. I guess I need to edit the connection string during runtime, but I am not sure. I have not done anything like this before, and I cannot find the information about it.

如果有人可以将我发送到教程中或对应用程序安装完成后如何使用访问数据库进行简要说明.

If someone could send me to a tutorial or give a brief explanation of how to use an access database once the application has been installed.

我的程序运行时,它将在

When my program runs, it creates a directory in

User\App Data\Roaming\CreatedFolder\Resources\DatabaseFile.accdb

那么我如何在不知道App Data完整路径的情况下设置此路径?

So how do I set this path without knowing the full path up to App Data?

推荐答案

您可以使用

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Environment.GetEnvironmentVariable("APPDATA")

他们俩都应该返回类似的内容

They both should return something similar to

C:\Users\Gord\AppData\Roaming

因此您可以像这样构建连接字符串:

so you can build your connection string like this:

Dim dbPath = _
        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & _
        "\CreatedFolder\Resources\DatabaseFile.accdb"
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath

这篇关于如何使用应用程序复制访问数据库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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