943,824 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 9211
  • ASP.NET RSS
Feb 20th, 2008
0

Relative path of MS Access Database

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 20th, 2008
0

Re: Relative path of MS Access Database

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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 20th, 2008
0

Re: Relative path of MS Access Database

Server.MapPath("~\MyData\grades.mdb")
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005
Feb 20th, 2008
0

Re: Relative path of MS Access Database

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
Reputation Points: 10
Solved Threads: 4
Light Poster
dilipv is offline Offline
30 posts
since Feb 2008
Feb 21st, 2008
0

Re: Relative path of MS Access Database

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 21st, 2008
0

Re: Relative path of MS Access Database

Here:
ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 22nd, 2008
0

Re: Relative path of MS Access Database

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".
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Printing from as ASP.Net web page
Next Thread in ASP.NET Forum Timeline: How To Authenticate Clients to printing From Server Using ASP.NET C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC