473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Global Variables for SQL

102 64KB
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

4 1187
Luk3r
300 256MB
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
sc5502
102 64KB
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
Luk3r
300 256MB
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
sc5502
102 64KB
That was the problem. Thanks for your help.
May 13 '16 #5

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

Similar topics

1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
10
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
5
by: Richard A. DeVenezia | last post by:
Dear Experts: Suppose I have global variables: x1, x2, x3 and I have a function that needs to assign a value to a new global variable x4 something like function foo () { count = 0;
2
by: Patient Guy | last post by:
I have a library of functions representing a filesystem interface (essentially a file selection interface, to be used in opening/reading/writing/closing files). Heavily scripted HTML document...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
7
by: zeecanvas | last post by:
Hi, First of all: Yes, I know global variables are bad, but I've a huge amount of legacy code, and I've to maintain it _as_is_. I'm maintaining a big program. I moved all (program-wide scope)...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.