I am new to using visual basic with SQL, previously I have used Access.
I was wondering if anyone could answer these few questions for me.
If I was to create a login form asking for username and password, and then once that
Was supplied I then connect to my SQL Server using an ado connection, providing I didn’t close the form down (hid it instead), would my connection stay open all the time whilst my user is in my application?
And if I declared the adodb connection as a global variable, whatever form I am in, could I then just use this to call the connection
This function would open my connection when my users first enter my application
Private Sub Command6_Click()
If cnn.State = 1 Then
Dim rs As New ADODB.Recordset
Dim strsql As String
strsql = "Select * from Projects"
rs.Open strsql, cnn
Me.projectid = rs.Fields("ProjectId")
Me.txtname = rs.Fields("name")
Me.organisation = rs.Fields("organisation")
Set rs = Nothing
'Unable to establish a connection
Private Sub Form_Close()
If cnn.State <> 0 Then
Set cnn = Nothing
Private Sub Form_Open(Cancel As Integer)
If cnn.State <> 1 Then
Is this a good way of doing this rather than opening a new connection everytime I wanted to do something with SQL?