Connecting to a MDB

Discussion in 'Databases' started by kirkiwami, Feb 3, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi,

    I'm new to the forum and to DiscountASP.NET (signed up Feb1).

    I've developed a web site that uses a connection string in web.config. I set up the connection string to be dynamic or relative and not absolute. The reason is the directory structure on my development machine will not be the same as the directory structure in DiscountASP.net's environment. The following are the connection strings in the web.config file:



    <add key="ConnectionString" value="Provider=Microsoft.jet.oledb.4.0;Data Source=FILLIN"/>


    <add key="ConnectionStringPath" value="/db/my.mdb"/>


    The following is the code that accesses the web.config file.


    ================================================


    ...





    ' Retrieve the 'Relative' connection string from the web.config file


    sConStr = ConfigurationSettings.AppSettings("ConnectionString")


    sPath = ConfigurationSettings.AppSettings("ConnectionStringPath")


    sActualPath = HttpContext.Current.Server.MapPath(sPath)


    sConStr = sConStr.Replace("FILLIN", sActualPath)


    Config.ConnectionString = sConStr


    ' Return the connection string


    Return Config


    ...


    ================================================


    This works fine on my development machine. I get the following error when the code is hosted:


    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


    Has anyone experienced this? Any suggestions would be appreciated.


    Thanks,


    Kirk
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Can you post the exact error?

    ALso post the line of code that crashes.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Bruce,

    I think the error is because the following statement does not work:



    sConStr = ConfigurationSettings.AppSettings("ConnectionString")


    This works fine on my development machine. It is not reading the connection string from my web.config file.


    The following is a portion of my web.config:


    <appSettings>


    <!-- Created 2 connection stringto make it 'relative' not absolute for the path -->


    <add key="ConnectionString" value="Provider=Microsoft.jet.oledb.4.0;Data Source=FILLIN"/>


    <add key="ConnectionStringPath" value="/db/nys.mdb"/>


    </appSettings>


    Thanks for any help,


    Kirk
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    Try dump out the sActualPath variable. I am suspecting the path is incorrect.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. Bruce or anyone,


    I found the problem, but I don't know how to solve it. Getting the connection string from the web.config file always returns string.empty. The following is the command I'm using:


    sConStr = ConfigurationSettings.AppSettings("ConnectionString")


    Inside the web.config file is the following:


    <appSettings>


    <!-- Created 2 connection stringto make it 'relative' not absolute for the path -->


    <add key="ConnectionString" value="Provider=Microsoft.jet.oledb.4.0;Data Source=FILLIN"/>


    <add key="ConnectionStringPath" value="/db/nys.mdb"/>


    </appSettings>
    Why does sConStr always return string.empty?

    Thanks,
    Kirk
     
  6. Issue solved. Thanks for everyones help.


    Kirk
     
  7. Could you post the solution for others that might have the same problem?


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  8. Solution:


    The web.config file was reloaded.


    Kirk
     
  9. tgo

    tgo

    I have exactly the same problem.
    What do you mean with 'The web.config file was reloaded' ?
    Thanks
     
  10. Bruce

    Bruce DiscountASP.NET Staff

    kirk may have some invalid information in the web.config file. That's what i suspect!

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  11. tgo

    tgo

    My problem is solved.
    It was due to the fact that IIS was installed after VS2005 (debugging was also unabled).
    I executed the command : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis -i
    and now everything is working!
     
  12. i am having the same problem. An empty connection string is returned when i try to access the web.config file.
    Urgent help needed.
    Thanx
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page