shlvy Posted August 18, 2004 Posted August 18, 2004 Hi I have a simple code that i want to convert it from a Virtual Path to Phisical Path: Sub Page_Load (Source As Object, E as EventArgs) Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("guestbook.mdb") & ";" Dim MySQL as string = "SELECT Name, EMail, URL, Comment FROM Guestbook" Dim MyConn as New OleDBConnection (strConn) Dim Cmd as New OleDBCommand (MySQL, MyConn) MyConn.Open () rptGuestbook.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection) rptGuestbook.DataBind() End Sub Can someone help me? Thank's. Quote
PWNettle Posted August 18, 2004 Posted August 18, 2004 Server.MapPath() should work for you...but if your database isn't in the root folder of your project you'd need to supply a full virtual path for it to get it properly "mapped", for ex: Dim sDbPath As String = Server.MapPath("/yourappfolder/yourdatafolder/yourdatabase.mdb") Paul Quote
*Gurus* Derek Stone Posted August 19, 2004 *Gurus* Posted August 19, 2004 Relative paths are the devil. Avoid them as you would the plague. Dim databasePath As String = Path.Combine(Application.PhysicalApplicationPath, "database\database.mdb") Quote Posting Guidelines
PWNettle Posted August 19, 2004 Posted August 19, 2004 (edited) It's Request.PhysicalApplicationPath I personally don't use Server.MapPath but it does exist, can be used, and was the context of the original question. If you're giving a relative virtual path that leads off with a slash it's relative to your virtual root. There's little question about how that path will be interpreted. I would agree that relative pathing in general can sometimes cause problems. Paul Edited August 19, 2004 by PWNettle Quote
*Gurus* Derek Stone Posted August 20, 2004 *Gurus* Posted August 20, 2004 Yep. My mistake on the class. Good catch. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.