[ Pobierz całość w formacie PDF ]
.It then passes the username and password to the driver, opening a connection.Once the connection is open, the connection component generates an AfterConnectevent, where you can perform any tasks that require an open connection.Note Some connection components generate additional events as well when establishing aconnection.Connec t i ng t o dat abases 23-3 Co n t r o l l i n g s e r v e r l o g i nOnce a connection is established, it is maintained as long as there is at least one activedataset using it.When there are no more active datasets, the connection componentdrops the connection.Some connection components surface a KeepConnectionproperty that allows the connection to remain open even if all the datasets that use itare closed.If KeepConnection is True, the connection is maintained.For connections toremote database servers, or for applications that frequently open and close datasets,setting KeepConnection to True reduces network traffic and speeds up the application.If KeepConnection is False, the connection is dropped when there are no active datasetsusing the database.If a dataset that uses the database is later opened, the connectionmust be reestablished and initialized.Disconnecting from a database serverThere are two ways to disconnect a server using a connection component:" Set the Connected property to False." Call the Close method.Calling Close sets Connected to False.When Connected is set to False, the connection component generates a BeforeDisconnectevent, where you can perform any cleanup before the connection closes.For example,you can use this event to cache information about all open datasets before they areclosed.After the BeforeConnect event, the connection component closes all open datasets anddisconnects from the server.Finally, the connection component generates an AfterDisconnect event, where you canrespond to the change in connection status, such as enabling a Connect button inyour user interface.Note Calling Close or setting Connected to False disconnects from a database server even ifthe connection component has a KeepConnection property that is True.Controlling server loginMost remote database servers include security features to prohibit unauthorizedaccess.Usually, the server requires a user name and password login beforepermitting database access.At design time, if a server requires a login, a standard login dialog box prompts for auser name and password when you first attempt to connect to the database.At runtime, there are three ways you can handle a server s request for a login:" Let the default login dialog and processes handle the login.This is the defaultapproach.Set the LoginPrompt property of the connection component to True (thedefault) and add DBLogDlg to the uses clause of the unit that declares theconnection component.Your application displays the standard login dialog boxwhen the server requests a user name and password.23-4 Devel oper  s Gui de Co n t r o l l i n g s e r v e r l o g i n" Supply the login information before the login attempt.Each type of connectioncomponent uses a different mechanism for specifying the user name andpassword:" For BDE, dbExpress, and InterBase express datasets, the user name andpassword connection parameters can be accessed through the Params property.(For BDE datasets, the parameter values can also be associated with a BDE alias,while for dbExpress datasets, they can also be associated with a connectionname)." For ADO datasets, the user name and password can be included in theConnectionString property (or provided as parameters to the Open method).If you specify the user name and password before the server requests them, besure to set the LoginPrompt to False, so that the default login dialog does notappear.For example, the following code sets the user name and password on aSQL connection component in the BeforeConnect event handler, decrypting anencrypted password that is associated with the current connection name:procedure TForm1.SQLConnectionBeforeConnect(Sender: TObject);beginwith Sender as TSQLConnection dobeginif LoginPrompt = False thenbeginParams.Values['User_Name'] := 'SYSDBA';Params.Values['Password'] := Decrypt(Params [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • funlifepok.htw.pl
  •