Connection string for Access not saved in App_Data

Last post 10-27-2009 10:10 AM by john6630. 0 replies.

Sort Posts:

  • Connection string for Access not saved in App_Data

    10-27-2009, 10:10 AM
    • Member
      point Member
    • john6630
    • Member since 09-28-2007, 11:36 AM
    • Posts 20

    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

Page 1 of 1 (1 items)