When I open a form where I refer to a public connection string, Visual studio tells me: The Variable 'JMSConnection' is either undeclared or was never asigned.
Does it work, because I get the same notifications with my global variables I declare in a global module but the project still works. I have just ignored them.
My suggestion is not to use Global Modules. Modules are a carry-over from VB6 - not very object-oriented at all.
If you must use global variables for the connection string, create a class that is marked MustInherit so that you don't try to instantiate it. From within this class, create Public Shared objects. I don't recommend puting complex objects here because I think it muddies up the code, but if you need to, place a connection string within this class.
As another alternative, I would create your own class that encapsulates all of your db connections and commands for your project. Instantiate this class when needed and pass references to the class object as needed.
Finally, another interesting way to keep app data around within an app is to create a DataSet object with schema organized to store information such as db settings, applciation settings, user preferences. I liek doing this in some situations because if I need to dump these settings into a easily-read format, I can use the DataSet.WriteXML() function to easily dump the current applicaiton state to a file. Elegant and easy - plus you can then share these application settings between programs. If you're concerned with storing passwords in the xml files, then you could encrypt the output stream of WriteXML with the RijndaelManaged class before it's written to disk. After writing the encrypted file to disk, the user can carry aorund their settings file on a USB keychain in case they move between PCs.
Would you have an app example of this concept? I guess I am a legacy VB6 programmer because I have been using globals forever and always up to learning the newer, correcter way.
How you use what I call global variables. A variable that can be used and changed by different forms and then used in the sql selects. I would also be interested in the use of the connection strings. Obviously can be fake, I don't need yours but I would like to use the proper methodology for .net if globals are wrong.
Here's an example app with a few forms - I've forgone the encryption, but there's three sections: the Utility shared class I described, the dbconnection class that you could use, then the XML file application data form wher eit autoloads xml files to remember credentials when it opens.