M
Martin
Hi Group
I apologize for this very basic (I guess) question. I had a look in
the posts and on MSDN but don't know where to start. I'm grateful for
any push in the right direction. I just don't know what I need to do.
Thank you so much!
Let's assume I've a procedure in class A which does some database
manipulation. When I run the procedure I want to open a SQL connection
and run some code. Since I have more than one procedure which opens a
connection, I don't want to write the code for opening a connection
all over again and I thought I put it in a separate class file B.
The class file B looks something like this:
Public Class clsData
Public Sub OpenSQLConection()
Dim SQLConnection As New System.Data.SqlClient.SqlConnection
SQLConnection.ConnectionString = "workstation
id=THEINTREPIDFOX;packet size=4096;user id=sa;data
source=""(local)"";p" & _
"ersist security info=False;initial catalog=Test"
SQLConnection.Open()
End Sub
Public Sub CloseSQLConnection()
Dim SQLConnection As System.Data.SqlClient.SqlConnection
SQLConnection.Close()
End Sub
End Class
-------------------------------------------------------------------------------
The code for class A from which I call the open database procedure is:
Imports TestApplication.clsData
Public Class clsValidate
Public Sub DataManipulation()
'Open database connection
clsData.OpenSQLConnection()
...Run Code
'Close database connection
clsData.CloseSQLConnection
End Sub
End Class
-------------------------------------------------------------------------------
How can I get the instance of the open connection so I can tell the
application under '...Run Code' that it shall use the connection being
opened in clsData?
How do I tell the CloseSQLConnection() procedure to close this very
open connection??
Apologies again for this simple question. I bet there are much more
errors in the code above. Please don't be too hard on me.
I apologize for this very basic (I guess) question. I had a look in
the posts and on MSDN but don't know where to start. I'm grateful for
any push in the right direction. I just don't know what I need to do.
Thank you so much!
Let's assume I've a procedure in class A which does some database
manipulation. When I run the procedure I want to open a SQL connection
and run some code. Since I have more than one procedure which opens a
connection, I don't want to write the code for opening a connection
all over again and I thought I put it in a separate class file B.
The class file B looks something like this:
Public Class clsData
Public Sub OpenSQLConection()
Dim SQLConnection As New System.Data.SqlClient.SqlConnection
SQLConnection.ConnectionString = "workstation
id=THEINTREPIDFOX;packet size=4096;user id=sa;data
source=""(local)"";p" & _
"ersist security info=False;initial catalog=Test"
SQLConnection.Open()
End Sub
Public Sub CloseSQLConnection()
Dim SQLConnection As System.Data.SqlClient.SqlConnection
SQLConnection.Close()
End Sub
End Class
-------------------------------------------------------------------------------
The code for class A from which I call the open database procedure is:
Imports TestApplication.clsData
Public Class clsValidate
Public Sub DataManipulation()
'Open database connection
clsData.OpenSQLConnection()
...Run Code
'Close database connection
clsData.CloseSQLConnection
End Sub
End Class
-------------------------------------------------------------------------------
How can I get the instance of the open connection so I can tell the
application under '...Run Code' that it shall use the connection being
opened in clsData?
How do I tell the CloseSQLConnection() procedure to close this very
open connection??
Apologies again for this simple question. I bet there are much more
errors in the code above. Please don't be too hard on me.