how to link to access database file in created .ex

2019-09-18 00:49发布

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");

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?

1条回答
神经病院院长
2楼-- · 2019-09-18 01:19

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. 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 step1 step2

查看更多
登录 后发表回答