locked
Connection string for Access not saved in App_Data RRS feed

  • Question

  • User514671716 posted

    Our host is GoDaddy. When you enable Access they create a subdirectory "access_db". You then have to create a connection string with a relative path to this directory. I searched for a full day before finding a solution, so I wanted to share what I found and get any feed back from the experts.

    Before showing the code, can anyone tell me why GoDaddy insists on using this directory instead of using App_Data or allowing me to create App_Data and giving it full pernissions? Seems pretty dumb to me not to be support the main technique used in ASP.Net. Anyway...

    In the Web.Config file replace the normal "|DataDirectory|" with the format string "{0}"

    <connectionStrings>
            <add name="YouConnStringName" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\your_database_name.mdb;Persist Security Info=False" providerName="System.Data.OleDb"/>
        </connectionStrings>

    In your data access code put the following:

    Private thePath As String = HttpContext.Current.Server.MapPath("access_db")
    ConnString = ConfigurationManager.ConnectionStrings("YouConnStringName").ConnectionString
    ConnString = String.Format(ConnString, thePath)

    I found this idea on the DiscountASP.Net fourms. Thanks.

    John

    Tuesday, October 27, 2009 10:10 AM

All replies

  • User771898575 posted

    Thanks for sharing, i am also a godadday customer

    Tuesday, January 5, 2010 12:10 AM
  • User-1199946673 posted

    can anyone tell me why GoDaddy insists on using this directory instead of using App_Data or allowing me to create App_Data and giving it full pernissions?
     

    I'm sure that Godaddy could tell you this. Did you ask them already?

    In your data access code put the following:

    Private thePath As String = HttpContext.Current.Server.MapPath("access_db")
    ConnString = ConfigurationManager.ConnectionStrings("YouConnStringName").ConnectionString

    In the Web.Config file replace the normal "|DataDirectory|" with the format string "{0}"

    Why not find out what thePath is filled with, and put that in your web.config instead of the placeholder {0}?

    Sunday, February 21, 2010 9:11 PM