none
how to access msaccess db from application path, please give me solution urgently RRS feed

  • Question

  • Hi All,

    I am working winforms with c#.net and msaccess db.

    i have to access db from application folder i don't specify the directory staticwise.

    i have written code for accessing the db following that is Appconfig file.

    I have taken connection string from this.

    ---------------------------

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    	<configSections>
     </configSections>
     <appSettings>
    	 <!-- <add key="ConnectStringToDB" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|IKON.mdb"/>-->
      <!-- <add key="ConnectStringToDB" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\IKON.mdb"/>-->
    	  <add key="ConnectStringToDB" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|App_Data\IKON.mdb;Persist Security Info=False"/>
    
    	</appSettings>
      <connectionStrings>
    
    		
    		<add name="ConnectStringToDB" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|App_Data\IKON.mdb;Persist Security Info=False"
          providerName="System.Data.OleDb" />
      </connectionStrings>
    </configuration>
    -------------

    My DB is in the debug folder.

    I f i put the above code I am accessing the DB and Alse working when i am running the apllication. and i closed the application and run again but i am lossing the data when i inserted first time data.

    If i put the directory path in some specified directory(C,D,E) then my application is working fine.

    Please give the solution for Lossing the data.

    I thing I did't give the file directory correctly Please give the solution with code.

    Thanks in Advance.

     

     

    Tuesday, June 8, 2010 2:40 PM

Answers

  • Hi RudraMurthy,

    I think the problem lies in "Data Source=|DataDirectory|IKON.mdb"/>-->", you have two ways to modify it:

    First is to specify the absolute path of the mdb, eg. DataDirectory|App_Data\IKON.mdb

    Second is to put you .mdb file the same with the .exe file, thus you just need the relative path of the .mdb which is known by Application.StartupPath property.

    Sincerely,
    Helen Zhou


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Helen Zhou Tuesday, June 15, 2010 2:42 AM
    Tuesday, June 15, 2010 2:42 AM