PDA

View Full Version : Connecting to a MDB


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

bruce
02-03-2006, 10:36 AM
Can you post the exact error?

ALso post the line of code that crashes.

Bruce

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

kirkiwami
02-03-2006, 11:14 AM
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

bruce
02-04-2006, 02:31 AM
Try dump out the sActualPath variable. I am suspecting the path is incorrect.

Bruce

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

kirkiwami
02-04-2006, 05:02 AM
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

kirkiwami
02-04-2006, 06:11 AM
Issue solved. Thanks for everyones help.


Kirk

joelnet
02-06-2006, 08:26 AM
Could you post the solution for others that might have the same problem?


Joel Thoms

DiscountASP.NET
http://www.DiscountASP.NET

kirkiwami
02-06-2006, 09:21 AM
Solution:


The web.config file was reloaded.


Kirk

tgo
03-21-2006, 06:50 AM
I have exactly the same problem.
What do you mean with 'The web.config file was reloaded' ?
Thanks

bruce
03-21-2006, 08:36 AM
kirk may have some invalid information in the web.config file. That's what i suspect!

Bruce

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

tgo
03-21-2006, 09:27 AM
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!

Abby_kn
08-20-2007, 07:40 AM
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