By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Global Variables for SQL

100+
P: 102
I am somewhat new to VB.NET. I need a little help if what I am wanting to do is possible.

I know what global variables are and use them in my projects. Is it possible to write global variables once and incorporate them into multiple projects.

I am wanting to do this with SQL parameters that rarely if never change. Here is one for example:

Expand|Select|Wrap|Line Numbers
  1. Public gSQLExpeditedShipments As String = "Server=TechDev01;Database=Expedited Shipments;Trusted_Connection=True"  ' Expedited Shipments
  2.     Public gSQLConnVersionControl As String = "Server=TechDev01;Database=VersionControl;Trusted_Connection=True"  ' Version Control Database
  3.  
gSQLExpeditedShipments is used as the connection string to SQL server. It is used over and over again in many projects. Now let's say the database folks are the are going to move this database to a new SQL Server. If this one variable is used in multiple projects then one would have to go in and change it the projects. Let's say there are 15 projects that use it. That would mean 15 projects have to change.

Can this and other static parameters be put in a single location and be used by all the projects that use it? This way it would only have change once.

Any help would greatly be appreciated. Thanks in advanced.
May 12 '16 #1

✓ answered by Luk3r

Did you add a reference to the ClassLibrary1.dll file? Right click your project name (i.e.; WindowsApplication1), choose Add Reference, click on the Browse tab, browse to the location of your ClassLibrary1.dll and click OK

Share this Question
Share on Google+
4 Replies


100+
P: 299
There is a very quick method that should work fine for you, Class.
1) Create a new VB.NET project and choose "Class Library"
2) In the public class, declare a shared variable similar to this:
Expand|Select|Wrap|Line Numbers
  1. Public Shared testStr As String = "testString"
3) Save and build this project
4) Inside your original project, add a reference to the class by browsing for the file and choosing the .dll that was created when you compiled your Class Library.
5) Also inside your original project, call the class by doing something similar to this:
Expand|Select|Wrap|Line Numbers
  1. MsgBox(ClassLibrary1.Class1.testStr)
As long as you put the .dll (Class Library) in a shared location, each time you want to make a global update, simply re-compile the Class Library and replace the old .dll with the new .dll and all of your projects will read the changes.
May 13 '16 #2

100+
P: 102
I did as said to do and I get the following error message:
Error 1 'ClassLibrary1' is not declared. It may be inaccessible due to its protection level.
Expand|Select|Wrap|Line Numbers
  1. Imports TestSQL
  2. Public Class Form1
  3.  
  4.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5.         MsgBox(ClassLibrary1.Class1.testStr)
  6.     End Sub
  7. End Class
  8.  
May 13 '16 #3

100+
P: 299
Did you add a reference to the ClassLibrary1.dll file? Right click your project name (i.e.; WindowsApplication1), choose Add Reference, click on the Browse tab, browse to the location of your ClassLibrary1.dll and click OK
May 13 '16 #4

100+
P: 102
That was the problem. Thanks for your help.
May 13 '16 #5

Post your reply

Sign in to post your reply or Sign up for a free account.