0

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?

fassetar
  • 615
  • 1
  • 10
  • 37
Hunar A. Ahmad
  • 35
  • 4
  • 11
  • I think you'd better use |DataDirectory| instead of defining the address this way. Source=|DataDirectory|\db_file.accdb – Transcendent Aug 21 '13 at 13:51
  • i use |DataDirectory|\db_file.accdb in my app.config file but it can not connect to db file? – Hunar A. Ahmad Aug 21 '13 at 14:02
  • Is your database located exactly where your application's executable file is? Otherwise you have to define the path after |DataDirectory| – Transcendent Aug 21 '13 at 14:13
  • @Bytes Oracle can you explain for me how i do this in detail where to put db file? how to config db file link in app.config file? how to call it in my forms? my db file db_file.accdb – Hunar A. Ahmad Aug 21 '13 at 14:22
  • 1
    I would recommend you to read the link I attached, I think it can solve your problem. http://social.msdn.microsoft.com/Forums/windows/en-US/3f9608fe-03d6-4a72-ab35-ec6ca7969a05/how-to-use-appconfig-file-for-set-database-connection – Transcendent Aug 21 '13 at 14:32
  • i create folder called Data inside my project folder i put database file in Data folder and i use `` in my app.config file. konw when i open the project if i do any operation it says it can not connect to the db_file ?? – Hunar A. Ahmad Aug 21 '13 at 14:52
  • can any answer and help me? – Hunar A. Ahmad Aug 21 '13 at 18:35

1 Answers1

0

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

Community
  • 1
  • 1
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81