kirkiwami
02-03-2006, 10:20 AM
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
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