| | |
Relative path of MS Access Database
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
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?
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?
•
•
Join Date: Feb 2008
Posts: 30
Reputation:
Solved Threads: 4
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
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.
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Here:
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
ASP.NET Syntax (Toggle Plain Text)
this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("\MyData\grades.mdb");
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
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".
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".
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
Other Threads in the ASP.NET Forum
- Previous Thread: Printing from as ASP.Net web page
- Next Thread: How To Authenticate Clients to printing From Server Using ASP.NET C#
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 ajax alltypeofvideos anathor appliances application asp asp.net bc30451 beginner box browser button c# cac checkbox commonfunctions complex control dataaccesslayer database datagridview datalist deployment development dgv dialog dropdownlist dynamic dynamically edit editing embeddingactivexcontrol expose feedback fileuploader fill findcontrol flash form formatdecimal formview google gridview gudi iis image javascript list listbox login microsoft mobile mouse mssql news novell numerical opera panelmasterpagebuttoncontrols parent project radio redirect registration relationaldatabases reportemail response.redirect richtextbox rows schoolproject search security select sessionvariables silverlight smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net videos vista visualstudio web webapplications webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






