Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I know this may sound funny but, as a newbie in using VB (6months old), without proper teaching or learning guides,

I do call my db connection everytime I open a form.

If i have 5 forms, then i will open my connection 5 times or more than, and releases it when the opened form is closed..

How can i do opening my db connection on my Main form, then when i clck on the other form, the connection string that i opened on my Main Form is recognized and read.

Here's my code

VB
Public Shared oCon As New OleDb.OleDbConnection
Public Shared oDs As New DataSet
Public Shared oDa As OleDb.OleDbDataAdapter
Public Shared oSQL, oTblName As String


Private Sub DBConn()
C#
oCon.ConnectionString = "Provider=SQLOLEDB;UID=sa;PWD=citadbo;Initial Catalog=Citadeldbo;Data Source=ANALYST04NEW\SQLEXPRESS"
oCon.Open()

End Sub

DBConn() is then called at the Form's Load Event, Disposes when the form is released.

And to which i repeatedly copy and paste to my other forms.
Posted
Updated 17-Aug-11 15:05pm
v2

1 solution

One option is to save your connection string in the app.config file and reference it from there...

Here's an article about how to do this: Configuration Settings File for providing application configuration data[^]
 
Share this answer
 
v2
Comments
Alan Tuscano 17-Aug-11 22:54pm    
If its okay, could you give me way to do it..
_Damian S_ 17-Aug-11 23:41pm    
Here's an article on it... http://www.codeproject.com/KB/dotnet/config.aspx
Alan Tuscano 18-Aug-11 2:26am    
Thanks Damian...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900