Solved

Connection string public module not working.

Posted on 2004-09-29
5
167 Views
Last Modified: 2012-05-05
I have 2 .aspx pages that are populating their data connection string using a public constant that's stored in a module and am encountering mysterious behavior.  For some reason, one of the pages doesn't detect the constants in the module.

Page #1 is older and works correctly, but Page #2 was just added and is giving me "[constant] has not been declared" error message.  The codebehinds of the pages are almost identical, but the newer one isn't detecting the constant in the module, no matter how many times I rebuild the project (including deleting the old DLL, just to be on the safe side).

The place where it breaks in each code behind is:
>    Dim sqlConn As New SqlConnection(PROVIDER_NAME)
 

The module in question looks like this:

>      Public Module Common
>        Public Const PROVIDER_NAME = "Initial Catalog=Client1;Data Source=WHATEVER;user id=blah;password=blah"
>        Public Const CATALOG_NAME = "Client1"
>       [...]
>      End Module

Any idea what the problem is?

Also, what's the word on modules in ASP.Net?  Are they buggy?

Thanks.



 
0
Comment
Question by:Leprechaun
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
GohdanTheMoblin earned 125 total points
ID: 12186258
Try prefixing the variables with the module name, like Common.PROVIDER_NAME.  If this fixes it, then just put an Imports <yournamespace>.Common at the top of your code file.
0
 

Author Comment

by:Leprechaun
ID: 12186336
Thanks, Gohdan.  

I ended up working around it by putting the connection string value in the Web.Config file instead.  But I'll try your fix.

BTW, is there any reason to avoid modules?  If find this behavior odd, so I'm wondering if I'm better off avoiding them.
0
 
LVL 2

Expert Comment

by:GohdanTheMoblin
ID: 12186348
I'm not sure if ASP has specific issues, but I know that from what I've heard and read, use of Modules is discouraged and Microsoft may remove them from VB.  A class with shared members accomplishes the same thing, and fits into the whole object-oriented design better.
0
 

Author Comment

by:Leprechaun
ID: 12190179
That's what I thought.  I actually inherited the code from a developer who works mostly in VB 6.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question