locked
OleDbConnection - Server.Mappath RRS feed

  • Question

  • User-565927763 posted

    Hi, . I want to make an oledbconnection for my access database. I want to put the connection string in the web.config but I learned that server.mappath does not work in there. I want to use the server.mappath. Can I put the connection sting in a session variable into the global.asax in the session start??

    Thursday, May 6, 2010 12:43 AM

Answers

  • User624841477 posted

    No do not put it in session since there is the way to store your connection string in web.config.

    If server.mappath doesn't works you can use Page.MapPath.

    folowing url will help u..

    http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx


    hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 6, 2010 1:45 AM
  • User-1199946673 posted

    I want to use the server.mappath
     

    Instead of server.mappath, use a tilde (~) . The tilde points to root of your website, so when your website is located in "C:\websites\domain\wwwroot", you can replace that with "~"

    But when you're putting database inside the root of your website, the only logical place is the App_Data folder, which will protect the database form downloading directly. So you could use "~/App_Data/db.mdb" in your connectionstring. But instead, you can also use "|DataDirectory|db.mdb". The DataDirectory Directive points to the App_Data folder in your root.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 6, 2010 10:39 AM

All replies

  • User624841477 posted

    No do not put it in session since there is the way to store your connection string in web.config.

    If server.mappath doesn't works you can use Page.MapPath.

    folowing url will help u..

    http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx


    hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 6, 2010 1:45 AM
  • User-1199946673 posted

    I want to use the server.mappath
     

    Instead of server.mappath, use a tilde (~) . The tilde points to root of your website, so when your website is located in "C:\websites\domain\wwwroot", you can replace that with "~"

    But when you're putting database inside the root of your website, the only logical place is the App_Data folder, which will protect the database form downloading directly. So you could use "~/App_Data/db.mdb" in your connectionstring. But instead, you can also use "|DataDirectory|db.mdb". The DataDirectory Directive points to the App_Data folder in your root.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 6, 2010 10:39 AM