Solved

Connection string public module not working.

Posted on 2004-09-29
5
164 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

862 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

23 Experts available now in Live!

Get 1:1 Help Now