[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Connection string public module not working.

Posted on 2004-09-29
5
Medium Priority
?
173 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
4 Comments
 
LVL 2

Accepted Solution

by:
GohdanTheMoblin earned 500 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

872 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