473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Help for ConfigurationManager in VB.Net 2005

After creating the ConnectionString node in Web.Config file (ASP.NET 2005) even after import System.Configuration

I am not able ot see the ConfigurationManager as a class, so that I can read the node for creating a DB connection. Any advice is appreciated. Thanks.
Oct 17 '07 #1
8 5194
By mistake I have posted the Question to this section of .Net forum. Can somebody move it for me to .Net Questions Forum please? Thanks.
Oct 17 '07 #2
Frinavale
9,735 Expert Mod 8TB
I've moved your thread as requested.
You should refrain from double posting your questions.


Are you retrieving your connection string using:
Expand|Select|Wrap|Line Numbers
  1. Dim myConString As String = ConfigurationManager.ConnectionStrings("MyDatabaseConnectionStringIdentifier").ConnectionString
  2.  
Where are you attempting to access the ConfigurationManager (please note that in certain places it is unavailable...like some functions in your Global.asax file)
Could you please provide more details about your problem.

-Frinny
Oct 17 '07 #3
Thanks Frinny for following it up.

For making DB connection, I have placed my connectionString in web.config as:

Expand|Select|Wrap|Line Numbers
  1. <connectionStrings>
  2.        <add name="MyDBConnection" connectionString="server=Server1; database=Req1; uid=sa; pwd=;" />
  3. </connectionStrings>
Now I have created a seperate project "DBConnect" and in the Class file DBConnect.vb I was writing this function for connecting to DB as:

Expand|Select|Wrap|Line Numbers
  1. Public Shared Function getConnectionObj() As SqlConnection
  2.    Dim objSqlConn as SqlConnection
  3.    Dim strConn as string
  4.  
  5.    strConn = ConfigurationManager.ConnectionStrings("MyDBConnection").ConnectionString
  6.  
  7.   objSqlConn = New SqlConnection(strConn)
  8.  
  9. End Function
But in the function code above I am NOT able to get the "ConfigurationManager" to read the node from Web.Config file. Please Help.

Also I have imported following libraries:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Configuration
  3. Imports System.Web
Oct 17 '07 #4
Plater
7,872 Expert 4TB
Now I have created a seperate project "DBConnect" and in the Class file DBConnect.vb I was writing this function for connecting to DB as:
You are in a seperate project? Values contained in a web.config apply only to the project it's contained in.
(Unless I'm mistaken)
Oct 17 '07 #5
Frinavale
9,735 Expert Mod 8TB
Thanks Frinny for following it up.

For making DB connection, I have placed my connectionString in web.config as:

Expand|Select|Wrap|Line Numbers
  1. <connectionStrings>
  2.        <add name="MyDBConnection" connectionString="server=Server1; database=Req1; uid=sa; pwd=;" />
  3. </connectionStrings>
Now I have created a seperate project "DBConnect" and in the Class file DBConnect.vb I was writing this function for connecting to DB as:

Expand|Select|Wrap|Line Numbers
  1. Public Shared Function getConnectionObj() As SqlConnection
  2.    Dim objSqlConn as SqlConnection
  3.    Dim strConn as string
  4.  
  5.    strConn = ConfigurationManager.ConnectionStrings("MyDBConnection").ConnectionString
  6.  
  7.   objSqlConn = New SqlConnection(strConn)
  8.  
  9. End Function
But in the function code above I am NOT able to get the "ConfigurationManager" to read the node from Web.Config file. Please Help.

Also I have imported following libraries:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Configuration
  3. Imports System.Web
Wow this sound familiar.
I did something very similar just a few months ago.
I wrote a class library in a project that managed all of my database manipulation. It was used within an asp.net project...and for security reasons I wanted to store the connection string in the web.config file.

What I ended up doing was passing the connection string to the class library functions from my asp.net project.

I don't think there is a way for both applications to access the connection strings node in the a web.config file.

(think about it ...would you want to allow any application access to this information? it could be malicious and destroy your database!)

I'll help you research the topic but I'm pretty sure that you can't do this.
Oct 17 '07 #6
Trying to do something like this in the DBManager Class:

Expand|Select|Wrap|Line Numbers
  1.             Dim Path As String = "C:\DBInfo.xml"
  2.             Dim doc As System.Xml.XmlDocument
  3.             Dim nodeList As System.Xml.XmlNodeList
  4.  
  5.             Dim strConn As String
  6.             Dim objSqlConn As SqlConnection
  7.  
  8.             doc = New XmlDocument()
  9.             doc.Load(Path)
  10.             node = doc.SelectSingleNode("Database/DB")
  11.             strConn = node.FirstChild.FirstChild.Value
This seems fine. But again I am hardcoding the File Path here in the vb file, which I don't want. I want to store this File Path info somewhere in a Configuration. Please advice. Thanks.
Oct 17 '07 #7
Plater
7,872 Expert 4TB
in the constructor for your dbmanager class (or just some public property) have it set the file path.
Then you can pass it in at runtime.
Oct 18 '07 #8
Thanks Plater. I shall try this out.
Oct 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Xtreeme-G | last post by:
I am seeing something weird in my c# winforms application. I cannot instantiate a ConfigurationManager object from the class. I have added System.Configuration in the uses section. I then try to...
1
by: Ben Fidge | last post by:
I recently upgraded a project from VS.NET 2003 to VS 2005 and after compilation I get the following warning: 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is...
0
by: John Peterson | last post by:
Hello! I'm a recent user of Visual Studio 2005, but I'm familiar with Visual Studio 2003. One of the things I'm wrestling with is the new configuration paradigm under VS2005 (.NET 2.0?). I'm...
2
by: Budhi Saputra Prasetya | last post by:
I'm using Visual C# 2005 Express Edition. I wanted to read configuration from app.config file. In 1.1, I used ConfigurationSettings, but in 2.0 I should use ConfigurationManager because...
4
by: Jim in Arizona | last post by:
I've been using VB 2005 for a few years now. My entire coding history is VB related. This weekend I decided to start learning C#. I'm at work now and decided to do some coding in C# that I would...
2
by: Toni | last post by:
Hello! I'm trying to use ASP.NET caching with my web site and SQL Server, but I have a problem. I try to do everything according to the instructions like this page here:...
0
by: Toni | last post by:
Hello! I'm trying to get caching work with ASP.NET 2.0 and SQL Server Express Edition 2005, but I have a problem and I can't figure out what I'm still doing wrong. I have enabled the database...
2
by: pantagruel | last post by:
Hi, I have a Visual studio 2005 project that runs as a Windows Service. In it I have declared that I am using System.Configuration. I have set one application setting for the service using the...
12
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.