如何使用C#链接访问已创建的.exe文件中的数据库文件 [英] how to link to access database file in created .exe file with c#

查看:217
本文介绍了如何使用C#链接访问已创建的.exe文件中的数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的C#项目创建安装文件.我在项目中使用Access 2010.我以我的项目的每种形式链接到数据库文件.这是我的数据库链接

I want to create setup file for my C# project. I use access 2010 with my project. I link to database file in every form of my project. This my database link

OleDbConnection db_con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data 
Source=C:\Users\HUNAR\Desktop\Bashi Nawxoyy\Bashi Nawxoyy\bin\Debug\db_file.accdb;Jet 
OLEDB:Database Password=RTm$&9sdfZXC;Persist Security Info=True");

知道创建安装文件时,我想在app.config文件中配置访问数据库文件并以每种形式调用它.我还想将db文件与安装文件一起附加,并且安装文件能够在安装了安装文件的每台机器上连接到db文件吗?

know in creation of setup file I want to config access database file in app.config file and call it in every form. Also I want to attach db file with the setup file and the setup file be able to connect to db file in every machine that i install the setup file on it?

推荐答案

如果要创建使用 MS Access数据库的 Dot Net 应用程序的.exe安装项目,请执行以下操作:强>.然后只需按照以下步骤操作即可.请先阅读一会,然后再继续执行这些步骤.

If you want to create .exe Setup Project of your Dot Net Application which is using MS Access DATA BASES. then simply follow this steps. Please read this one for a moment before to proceed these steps.Connect with MS Access Data Base in Dot net. When you are going to create the exe file then your data base connection string should be like this(means there should be no directory in @"Data source, Just direct put the name of your data base, because in .exe file when you add your data base file, then it is in the same directory.

   System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
    conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
     @"Data source=MyDataBase.accdb";

  1. 右键单击您的解决方案文件. (例如在解决方案资源管理器"Solution'MyProject'"中)
  2. 选择添加->新项目->其他项目类型
  3. 选择设置"
  4. 将添加一个名为setup的新项目(,其中添加了新标签 编辑器作为文件系统)
  5. 现在右键单击应用程序文件夹->选择添加->选择文件夹 新文件夹将添加到应用程序文件夹下*现在右键单击 在新添加的文件夹上->选择添加->选择文件*添加文件"对话框 将弹出
  6. 选择您的Db文件(意味着从那里的浏览"按钮中选择您的访问数据库)
  7. 选择安装项目并进行构建.现在,您的 安装程序将拥有您的数据库.
  1. Right click on your solution file. (like in Solution Explorer "Solution 'MyProject' ")
  2. Select Add -->New Project -->Other Project Types
  3. Select "Setup"
  4. A New project will be added named setup (with a new tab added to editor as File System )
  5. Now right click on application folder -->select add -->select folder new folder will be added under application folder * Now Right click on newly added folder -->select add -->select file * Add File dialog will be popup
  6. Select your Db file (means from a "Browse" Button there go and select your Access Data Base )
  7. Select Setup project and build.. Now your installer will have your DB.

一些屏幕快照将为您提供帮助

Some screen shot which will help you

这篇关于如何使用C#链接访问已创建的.exe文件中的数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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