How do I include this in a database component? I'm following along with Beginning ASP.net 2.0 C# by Apress. I've pasted in the code from the exercise below. I can complete the project fine using a class , but not as a stand alone component. I get the
following error: " The type or namespace "configuration" does not exist." I'm sure I'm missing something simple here, but it doesn't appear to me that a custom class library has a web.config, so I need some more code to grab the value from a web.config once
the data object is referenced in my application. Thanks in advance for any insight.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace DatabaseComponent
{
public
class
DBUtil
{
private
string connectionString;
public DBUtil()
{
connectionString = WebConfigurationMananger.ConnectionStrings["AdBoard"].ConnectionString;
}
}
To include it in a database component add a reference to system.Configuration dll to your project if it does not already exist and then replace WebconfigurationManager with just ConfigurationManager
Jeev
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you get the answer to your question, please mark it as the answer.
Is System.Web in your web references? (Website - Add Reference), if not you'll need to re-install .NET 2.0, or try adding the reference it's located in C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll
Personally I would re-install/repair .NET.
Remember to mark as answer the solution which helped you.
Did you add a reference to System.Configuration?If not,
1. Right click on the References in the object explorer and choose "Add Reference".
2. From the .NET tab choose System.Configuration and click ok.
This should work.
Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
Marked as answer by everett31 on Jul 25, 2008 02:57 PM
Thanks for the help. It works with ConfigurationMananger or WebConfigurationManager if the reference is added to the project. I figured it would be simple but sometimes I want to kick myself in the ***. Thanks again for the responses. This forum is
invaluable.
"Is System.Web in your web references? (Website - Add Reference), if not you'll need to re-install .NET 2.0, or try adding the reference it's located in C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll"
[:(]
Remember to mark as answer the solution which helped you.
everett31
Member
10 Points
26 Posts
using System.Web.Configuration
Jul 25, 2008 02:14 PM|LINK
Hello,
How do I include this in a database component? I'm following along with Beginning ASP.net 2.0 C# by Apress. I've pasted in the code from the exercise below. I can complete the project fine using a class , but not as a stand alone component. I get the following error: " The type or namespace "configuration" does not exist." I'm sure I'm missing something simple here, but it doesn't appear to me that a custom class library has a web.config, so I need some more code to grab the value from a web.config once the data object is referenced in my application. Thanks in advance for any insight.
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration; namespace DatabaseComponent
{
public class DBUtil
{
private string connectionString;
public DBUtil()
{
connectionString = WebConfigurationMananger.ConnectionStrings["AdBoard"].ConnectionString;
}
}
}
Jeev
All-Star
24182 Points
3719 Posts
Re: using System.Web.Configuration
Jul 25, 2008 02:23 PM|LINK
To include it in a database component add a reference to system.Configuration dll to your project if it does not already exist and then replace WebconfigurationManager with just ConfigurationManager
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you get the answer to your question, please mark it as the answer.
Som Nath Shu...
Contributor
3289 Points
541 Posts
Re: using System.Web.Configuration
Jul 25, 2008 02:23 PM|LINK
System.Web.Configuration.
WebConfigurationManager.use System.Web.Configuration. namespace.
Somnath
http://silverlightcsharp.blogspot.com
Please click “Mark as Answer” on the post if it helps you,
G0ggy
Participant
1081 Points
299 Posts
Re: using System.Web.Configuration
Jul 25, 2008 02:24 PM|LINK
Is System.Web in your web references? (Website - Add Reference), if not you'll need to re-install .NET 2.0, or try adding the reference it's located in C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll
Personally I would re-install/repair .NET.
Remember to mark as answer the solution which helped you.
keyrav
Member
170 Points
37 Posts
Re: using System.Web.Configuration
Jul 25, 2008 02:25 PM|LINK
Are you trying to access connection string in your class file ?
Try to access it like this.
ConnectionStringSettings s = ConfigurationManager.ConnectionStrings["Connstr"];
A2ZDotNet
santa_1975
Star
8574 Points
1499 Posts
Re: using System.Web.Configuration
Jul 25, 2008 02:32 PM|LINK
Did you add a reference to System.Configuration?If not,
1. Right click on the References in the object explorer and choose "Add Reference".
2. From the .NET tab choose System.Configuration and click ok.
This should work.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
everett31
Member
10 Points
26 Posts
Re: using System.Web.Configuration
Jul 25, 2008 03:02 PM|LINK
Thanks for the help. It works with ConfigurationMananger or WebConfigurationManager if the reference is added to the project. I figured it would be simple but sometimes I want to kick myself in the ***. Thanks again for the responses. This forum is invaluable.
G0ggy
Participant
1081 Points
299 Posts
Re: using System.Web.Configuration
Jul 25, 2008 03:03 PM|LINK
"Is System.Web in your web references? (Website - Add Reference), if not you'll need to re-install .NET 2.0, or try adding the reference it's located in C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll"
[:(]
Remember to mark as answer the solution which helped you.