In VB6 I use more Forms where users can Add, Edit, Delete Records from more tables.
WHICH IS THE BEST METHOD
1. To open a connection when user start the application and I close the connection when user leave the application.
In Login form (Public cn As ADODB.Connection)
SirConectare_SQL = "Provider=SQLOLEDB.1" & _
";Password='" & Pass & "'" & _
";Persist Security Info=False" & _
";User ID='" & UserName & "'" & _
";Initial Catalog='" & DataBaseName & "'" & _
";Data Source='" & ServerName & "'"
Set cn = New ADODB.Connection
With cn
.ConnectionString = SirConectare_SQL
.Open
End With
OR
2. To Open a connection in each Form and close the connection when Form is UnLoadetThe first case is not possible because
Set cn = New ADODB.Connection (this is in Form Login)
In other form it is necesary to set the connection again.|||The rule is that you only keep the connection open as long as needed - and no longer. What are your concerns ?|||How many clients will use this application ?|||5-8 users|||Will the security credentials be different for each user ? What is the purpose for the application and the multiple forms ? Are you thinking about opening 1 connection object that will be used for multiple recordset/command objects ?|||How I can open a connection when user start the application and kepp open until user leave the application ?
In module:
Public cn As ADODB.Connection
In first form when is load:
SirConectare_SQL = "Provider=SQLOLEDB.1" & _
";Password='" & Pass & "'" & _
";Persist Security Info=False" & _
";User ID='" & UserName & "'" & _
";Initial Catalog='" & DataBaseName & "'" & _
";Data Source='" & ServerName & "'"
Set cn = New ADODB.Connection
With cn
.ConnectionString = SirConectare_SQL
.Open
End With
If I want to use "cn" in other forms is not possible (is not open)|||Are you destroying/closing the connection before the 2nd form is loaded ?|||I don`t close the connection, but I close (Unload) the first form.
The connection is closed ?|||Where are you declaring - Public cn As ADODB.Connection ?|||This declaration is made on a Module
Public cn As ADODB.Connection
In the Startup Form (where user input UserName and Password)
Set cn = New ADODB.Connection
With cn
.ConnectionString = SirConectare_SQL
.Open
End With
If I want to use this connection on other forms I can't because is Closed.
I want to open the connection only one time(when application startup), and if it possible to use the connection in all form.|||Open the connection in a module or class when login in form successfull. Close it when application main form is closed.|||This Looks Like VB code If it is Do not forget to set the DBconnection ( and all all objects associated to it) = nothing
set cn = nothing
I personnally like to use 1 public DB connection instead of multiple connections per app.
Hope this helps.
LJ|||Hello Gurus out there!
I want to know what would be the best method in opening a connection to server:
1. a connection (declared globally) that is open once during Login and access thru all forms and be closed only when application is terminated
What is the advantage/disadvantage of this method in my SQL Server 2k resources or in any RDBMS?
2. a connection is opened only when needed but everytime i execute a query against the database i have to open also that connection and terminate when it is not used...What is the advantage/disadvantage of this method in my SQL Server 2k resources or in any RDBMS?
Secondly, how can we know the resources used by the users that are connected to my SQL SERVER in terms of memory usage and CPU?
Im using VB/FOxPro and I want to know the best practice in terms of opening a connection to the database coz Im expecting to have 20 or more users online simultanously and hook to my server as soon as we are finished with our system.
I hope you can light up our minds with these concerns.
Thanks,
Bernie|||Bernie - What driver are you using ?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment