VB.Net中的数据库问题 [英] Issues with Database in VB.Net

查看:59
本文介绍了VB.Net中的数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我在VB.Net和Access 2007中开发了一个应用程序,我在数据库中保存,编辑,搜索,更新和报告记录,一切正常,但是:

1.项目文件夹(myprojectname \ dbname)中有两个访问文件,中有一个(myprojectname \bin\debug \ dbname) 当我保存记录时,它正在保存但是在(myprojectname\bin\debug\dbname)数据库而不是(myprojectname \ dbname)当我再次运行项目时创建问题的数据库记录现在没有了。

我使用以下代码连接字符串

< ; br /> 
Imports System.Data.OleDb< br />
模块连接< br />
Public Con As OleDbConnection = New OleDbConnection(Provider = Microsoft.Ace.OLEDB.12.0 ; Data Source =& Application.StartupPath&\ mydb.accdb)< br />
< br />
End Mod ule< br />



我也试过

< br /> 
Public Con As OleDbConnection =新的OleDbConnection(Provider = Microsoft.Ace.OLEDB.12.0; Data Source = | DataDirectory | \mydb.accdb;)< br />



但是一切都是徒劳的。

现在,我请求你帮助我以正确的方式处理VB.Net中的访问2007数据库

注意: mydb。 aacdb 也在我的解决方案资源管理器中。



谢谢

解决方案

开始于不要将数据库存储在任何位置。这是一个糟糕的主意,因为它会给生产带来巨大的问题 - 应用程序将安装在Program Files文件夹中,该文件夹是为了安全而写保护的。



而不是,考虑使用更安全的地方:我应该在哪里存储我的数据? [ ^ ] - 它在C#中,但它在VB中几乎相同。


每次编译项目时,项目文件夹中的数据库文件都会在运行时复制到目标bin文件夹该应用程序。此操作将覆盖您上次运行应用程序时修改的文件数据库。



不要将数据库文件保留为项目的一部分。将数据库存储在计算机上所有用户均可访问的位置。请查看 Environment.GetFolderPath [ ^ ]方法和 CommonApplicationData [ ^ ]文件夹。

Hello everyone
I have developed an application in VB.Net and Access 2007 where I am saving ,editing,searching, updating and reporting records from the database and everything is working fine except:
1. There are two access files one in the project folder (myprojectname\dbname) and one in the (myprojectname\bin\debug\dbname) and when i save a record it is being saved but in the (myprojectname\bin\debug\dbname) database and not in (myprojectname\dbname) database which creates a problem when i run the project again the record is nowhere now.
I use the following code for connectionstring

<br />
Imports System.Data.OleDb<br />
Module connection<br />
    Public Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & Application.StartupPath & "\mydb.accdb")<br />
   <br />
End Module<br />


I also tried

<br />
    Public Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=|DataDirectory|\mydb.accdb;")<br />


but all in vain.
Now, i request you that please help me in the correct way of dealing with access 2007 database in VB.Net
Note: mydb.aacdb is also in my solution explorer.

Thank you

解决方案

Start off by not storing your DB in either location. It's a poor idea, as it will give huge problems in production - the application will be installed in the "Program Files" folder which is write protected for security.

Instead, consider using a "safer" place: Where should I store my data?[^] - it's in C#, but it's pretty much the same in VB.


Every time you compile your project the database file in the project folder is copied to the target bin folder when you run the app. This operation overwrites the file database you modified the last time you ran the app.

Don't keep your database file as part of the project. Store the database in a place that is accessible to all users on the machine. Look at the Environment.GetFolderPath[^] method and the the CommonApplicationData[^] folder.


这篇关于VB.Net中的数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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