Relative path of MS Access Database

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Relative path of MS Access Database

 
0
  #1
Feb 20th, 2008
Everytime I connect my Access database into my page for some SQL statements like SELECT, INSERT, UPDATE, and DELETE - I make use of an absolute path in my data source such as Data Source = C:\MyData\grades.mdb.

But when I make use of a relative path in my data source such as ~\MyData\grades.mdb, I always receive an OleDbException error message.

Am I doing it correctly? What should be the correct code to have a relative path to the Access Database?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Re: Relative path of MS Access Database

 
0
  #2
Feb 20th, 2008
Just a follow up, I am using C# as my script. I make use of OleDbConnection and OleDbCommand to facilitate my SQL transactions. How can I make use of relative path in MS Access?
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Relative path of MS Access Database

 
0
  #3
Feb 20th, 2008
Server.MapPath("~\MyData\grades.mdb")
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: dilipv is an unknown quantity at this point 
Solved Threads: 4
dilipv dilipv is offline Offline
Light Poster

Re: Relative path of MS Access Database

 
0
  #4
Feb 20th, 2008
hi ebabes,
I think problem exists in your connection string.Since you are using C# as your coding language then due to Escape sequence ('\') problem your connection string is not proper.
It should be like that.

this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~\\MyData\\grades.mdb");

OR

this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\\MyData\\grades.mdb";

Hope this will help you.
Thanks & Regards
Dilipv
Dilip Kumar Vishwakarma
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Re: Relative path of MS Access Database

 
0
  #5
Feb 21st, 2008
I tried the given code this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~\\MyData\\grades.mdb"); but I received an error message "The name Server does not exist in the current context".

Any remedy to this? Thanks.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Relative path of MS Access Database

 
0
  #6
Feb 21st, 2008
Here:
  1. this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("\MyData\grades.mdb");
You need to make sure that MyData is a folder in the root directory. This will specify the server's path to the root folder, then on from there is what you specified.

Example:
Let's say your server's physical path is: H:\inetpub\root\

By saying Server.MapPath, it will grab the above line. Then anything within the parenthesis will be added along side the server.mappath:
Server.MapPath("\MyData\grades.mdb")
=
H:\inetpub\root\MyData\grades.mdb
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Re: Relative path of MS Access Database

 
0
  #7
Feb 22nd, 2008
Thanks. I don't get any problem about the directory where I put my database. I only find a problem in the word "Server" because it is not accepted by the Web Developer when I insert the code in a class.

I wonder the code above is accepted when I insert it in a click event such as button click. But when I put the code else where in my class, there I receive the message "The word server does not exist in the current context".
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC