Greetings all,
I am working on a MDI application where I can have multiple screens open to many different parts of the application. Maintenance, orders, reports, etc...
Basically, I typically create an application that allows me to define my connection and recordset objects, as in the example below:
[ ---- code snippet start --- ]
' functions are scaled down drastically so as to not make a
' super long posting
Public ConSQL As ADODB.Connection
Public RstSQL As ADODB.Recordset
Public SQL As String
Public Function SQLInitConn() As Boolean
Dim mstrDBConnect As String
mstrDBConnect = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=dbasename"
Set ConSQL = New ADODB.Connection
Set RstSQL = New ADODB.Recordset
ConSQL.Open mstrDBConnect
Exit Function
End Function
Public Sub SQLCloseConn()
On Error Resume Next
RstSQL.Close
ConSQL.Close
Set RstSQL = Nothing
Set ConSQL = Nothing
End Sub
Public Sub SubmitQuery()
RstSQL.CursorLocation = adUseClient
RstSQL.Open SQL, ConSQL, adOpenKeyset, adLockOptimistic
End Sub
[ ---- code snippet end --- ]
Now that I have posted by snippet, I can explain my problem. If I have one form open, let's say customer maintenance, and I am loading a list of all available customers, but I want to run a report at the same time, the report will crash and not function because I only have one database connection available, and it's currently busy loading the customer list.
I had the bright idea (sarcastically speaking) to do something along these lines (see below):
Public ConSQL(1 to 10) As ADODB.Connection
Public RstSQL(1 to 10) As ADODB.Recordset
Public SQL As String
which I thought would allow me to essentially have an array of connections where I could use the ActiveConnection property to see if consql(1) was busy, and go on to consql(2), or consql(3) if consql(2) was busy, etc... Well, VB did not like that at all. It gave me an error about collections as soon as I tried to do something like rstsql(1)!fieldname.
Anyway, now that i've explained my attempts, and gotten frusterated trying to implement them, my question is this:
Can someone give me a small code snippet example of how I essentially can create dynamic database connections in the event that one form or another needs to access the database at the same time (without hosing the memory in the computer)? I was going to forget about using my SqlInitConn routine, and just immediately call the SubmitQuery function which would see if there was an open connection, then check if the recordset for the connection was busy and use that connection, or open another connection if needed. But, again, that didn't work.
Any help would be appreciated.
Thanks,
Pan
I am working on a MDI application where I can have multiple screens open to many different parts of the application. Maintenance, orders, reports, etc...
Basically, I typically create an application that allows me to define my connection and recordset objects, as in the example below:
[ ---- code snippet start --- ]
' functions are scaled down drastically so as to not make a
' super long posting
Public ConSQL As ADODB.Connection
Public RstSQL As ADODB.Recordset
Public SQL As String
Public Function SQLInitConn() As Boolean
Dim mstrDBConnect As String
mstrDBConnect = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=dbasename"
Set ConSQL = New ADODB.Connection
Set RstSQL = New ADODB.Recordset
ConSQL.Open mstrDBConnect
Exit Function
End Function
Public Sub SQLCloseConn()
On Error Resume Next
RstSQL.Close
ConSQL.Close
Set RstSQL = Nothing
Set ConSQL = Nothing
End Sub
Public Sub SubmitQuery()
RstSQL.CursorLocation = adUseClient
RstSQL.Open SQL, ConSQL, adOpenKeyset, adLockOptimistic
End Sub
[ ---- code snippet end --- ]
Now that I have posted by snippet, I can explain my problem. If I have one form open, let's say customer maintenance, and I am loading a list of all available customers, but I want to run a report at the same time, the report will crash and not function because I only have one database connection available, and it's currently busy loading the customer list.
I had the bright idea (sarcastically speaking) to do something along these lines (see below):
Public ConSQL(1 to 10) As ADODB.Connection
Public RstSQL(1 to 10) As ADODB.Recordset
Public SQL As String
which I thought would allow me to essentially have an array of connections where I could use the ActiveConnection property to see if consql(1) was busy, and go on to consql(2), or consql(3) if consql(2) was busy, etc... Well, VB did not like that at all. It gave me an error about collections as soon as I tried to do something like rstsql(1)!fieldname.
Anyway, now that i've explained my attempts, and gotten frusterated trying to implement them, my question is this:
Can someone give me a small code snippet example of how I essentially can create dynamic database connections in the event that one form or another needs to access the database at the same time (without hosing the memory in the computer)? I was going to forget about using my SqlInitConn routine, and just immediately call the SubmitQuery function which would see if there was an open connection, then check if the recordset for the connection was busy and use that connection, or open another connection if needed. But, again, that didn't work.
Any help would be appreciated.
Thanks,
Pan