Solved

Connection string public module not working.

Posted on 2004-09-29
5
163 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That's what I thought.  I actually inherited the code from a developer who works mostly in VB 6.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now