ADOÈý´ó¶ÔÏóµÄÊôÐÔ¡¢·½·¨¡¢Ê¼þ¼°³£Êý£¨Ò»£©
Connection¶ÔÏóÊôÐÔ ÊôÐÔÃû³Æ Êý¾ÝÀàÐͺÍÓÃ; Attributes ¿É¶ÁдLongÀàÐÍ£¬Í¨¹ýÁ½¸ö³£ÊýÖ®ºÍÖ¸¶¨ÊÇ·ñʹÓñ£ÁôÊÂÎñ£¨retainning transactions£©¡£³£ÊýadXactCommitRetaining±íʾµ÷ÓÃCommitTrans·½·¨Ê±Æô¶¯Ò»¸öÐÂÊÂÎñ£»³£ÊýadXactAbortRetaning±íʾµ÷ÓÃRollbackTrans·½·¨Ê±Æô¶¯Ò»¸öÐÂÊÂÎñ¡£Ä¬ÈÏֵΪ0£¬±íʾ²»Ê¹Óñ£ÁôÊÂÎñ¡£ CommandTimeout ¿É¶ÁдLongÀàÐÍ£¬Ö¸¶¨ÖÐֹij¸öÏà¹ØCommand¶ÔÏóµÄExecuteµ÷ÓÃ֮ǰ±ØÐëµÈ´ýµÄʱ¼ä¡£Ä¬ÈÏֵΪ30Ãë¡£ ConnectionString ¿É¶ÁдStringÀàÐÍ£¬ÌṩÊý¾ÝÌṩÕß»ò·þÎñÌṩÕß´ò¿ªµ½Êý¾ÝÔ´µÄÁ¬½ÓËùÐèÒªµÄÌض¨ÐÅÏ¢ ConnectionTimeout ¿É¶ÁдLongÀàÐÍ£¬Ö¸¶¨ÖÐÖ¹Ò»¸öʧ°ÜµÄConnection.Open·½·¨µ÷ÓÃ֮ǰ±ØÐëµÈ´ýµÄʱ¼ä£¬Ä¬ÈÏֵΪ15Ãë¡£ CursorLocation ¿É¶ÁдLongÀàÐÍ£¬È·¶¨ÊÇʹÓÿͻ§¶Ë(adUseClient)ÓαêÒýÇ棬»¹ÊÇʹÓ÷þÎñÆ÷¶Ë(adUseServer)ÓαêÒýÇ档ĬÈÏÖµÊÇadUseServer¡£ DefaultDatabase ¿É¶ÁдStringÀàÐÍ£¬Èç¹ûConnectStringÖÐδָ¶¨Êý¾Ý¿âÃû³Æ£¬¾ÍʹÓÃÕâÀïËùÖ¸¶¨µÄÃû³Æ£¬¶ÔSQL Server¶øÑÔ£¬Æäֵͨ³£ÊÇpubs IsolationLevel ¿É¶ÁдLongÀàÐÍ£¬Ö¸¶¨ºÍÆäËû²¢·¢ÊÂÎñ½»»¥Ê±µÄÐÐΪ»òÊÂÎñ¡£¼ûIsolationLevel³£Êý Mode LongÀàÐÍ£¬Ö¸¶¨¶ÔConnectionµÄ¶ÁдȨÏÞ¡£¼ûMode³£Êý Provider ¿É¶ÁдStringÀàÐÍ£¬Èç¹ûConnectionStringÖÐδָ¶¨OLE DBÊý¾Ý»ò·þÎñÌṩÕßµÄÃû³Æ£¬¾ÍʹÓÃÕâʱָ¶¨µÄÃû³Æ¡£Ä¬ÈÏÖµÊÇMSDASQL(Microsoft OLE DB Provider for ODBC)¡£ State ¿É¶ÁдLongÀàÐÍ£¬Ö¸¶¨Á¬½ÓÊÇ´¦ÓÚ´ò¿ª×´Ì¬£¬»¹ÊÇ´¦ÓڹرÕ״̬»òÖмä״̬¡£¼ûState³£Êý Version Ö»¶ÁStringÀàÐÍ£¬·µ»ØADO°æ±¾ºÅ¡£ ×¢Ò⣺ÉÏÃæËùÁгöµÄ´ó¶àÊý¿É¶ÁдµÄÊôÐÔ£¬Ö»Óе±Á¬½Ó´¦ÓڹرÕ״̬ʱ²ÅÊÇ¿ÉдµÄ¡£ Ö»Óе±Óû§ÎªConnection¶ÔÏóÓÃBeginTrans...CommitTrans...RollbackTrans·½·¨¶¨ÒåÁ˲»ÒÅÓàÁ¦£¬ÊÂÎñ¸ôÀë³Ì¶ÈµÄÖ¸¶¨²ÅÕæÕýÓÐЧ¡£Èç¹ûÓжà¸öÊý¾Ý¿âÓû§Í¬Ê±Ö´ÐÐÊÂÎñ£¬ÄÇôӦÓóÌÐòÖбØÐëÖ¸¶¨ÈçºÎÏìÓ¦ÔËÐÐÖеÄÆäËûÊÂÎñ¡£ ·½·¨ ·½·¨ ÓÃ; BeginTrans ³õʼ»¯Ò»¸öÊÂÎñ£»Æäºó±ØÐëÓÐCommitTransºÍ£¯»òRollbackTransÏàºôÓ¦ Close ¹Ø±ÕÁ¬½Ó CommitTrans Ìá½»Ò»¸öÊÂÎñ£¬ÒÔÍê³É¶ÔÊý¾ÝÔ´µÄÓÀ¾Ã¸Ä±ä£¨ÒªÇóʹÓÃ֮ǰ±ØÐëµ÷ÓÃÁËBeginTrans·½·¨) Execute ÈËSELECT SQLÓï¾ä·µ»ØÒ»¸öforward-only Recordset¶ÔÏó£¬Ò²ÓÃÀ´Ö´ÐÐÄÇЩ²»·µ»ØRecordsetÓï¾ä£¬ÈçINSERT¡¢UPDATE¡¢DELETE²éѯ»òDDLÓï¾ä Open ÓÃÁ¬½Ó×Ö·û´®À´´ò¿ªÒ»¸öÁ¬½Ó OpenSchema ·µ»ØÒ»¸öRecordset¶ÔÏóÒÔÌṩÊý¾ÝÔ´µÄ½á¹¹ÐÅÏ¢(metadata) RollbackTrans È¡ÏûÒ»¸öÊÂÎñ£¬»Ö¸´¶ÔÊý¾ÝÔ´×öµÄÁÙʱÐԸıä(ÒªÇóʹÓÃ֮ǰ±ØÐëµ÷ÓÃÁËBeginTrans·½·¨) ×¢£ºÖ»ÓÐExecute¡¢OpenºÍOpenSchemaÈý¸ö·½·¨²ÅÄܽÓÊܱäÔª²ÎÊý¡£ExecuteµÄÓ﷨Ϊ£º cnnName.Execute strCommand,[lngRowsAffected[,lngOptions]] strCommandµÄÖµ¿ÉÒÔÊÇSQLÓï¾ä¡¢±íÃû¡¢´æ´¢¹ý³ÌÃû£¬Ò²¿ÉÒÔÊÇÊý¾ÝÌṩÕßËùÄܽÓÊܵÄÈÎÒâ×Ö·û´®¡£ÎªÁËÌá¸ßÐÔÄÜ£¬×îºÃΪlngOptions²ÎÊýÖ¸¶¨ºÏÊʵÄÖµ£¨Ïê¼ûlngOptions²ÎÊýÓõ½µÄ³£Êý£©£¬ÒÔʹÌṩÕß½âÊÍÓï¾äʱ²»ÓÃÔÙÈ¥Åж¨ÆäÀàÐÍ¡£¿ÉÑ¡²ÎÊýlngRowsAffected½«·µ»ØINSERT¡¢UPDATE»òDELETE²éѯִÐÐÒÔºóËùÓ°ÏìµÄÊýÄ¿¡£ÕâЩ²éѯ»á·µ»ØÒ»¸ö¹Ø±ÕµÄRecordset¶ÔÏó¡£Ò»¸öSELECT²éѯ½«·µ»ØlngRowsAffectedֵΪ0²¢ÇÒ·µ»Ø´øÓÐÒ»Ðлò¶àÐÐÄÚÈݵĴò¿ªµÄforward-only Recordset¡£ ʼþ ʼþÃû³Æ ´¥·¢Ê±»ú BeginTransComplete BeginTrans·½·¨Ö´ÐÐÒÔºó¡£ Private Sub cnnName_BeginTransComplet(ByVal TransactionLevel As Long,ByVal pError As ADODB.Error,adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) CommitTransComplete CommitTrans·½·¨Ö´ÐÐÒÔºó Private Sub Connection1_CommitTransComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) ConnectComplete ³É¹¦½¨Á¢µ½Êý¾ÝÔ´µÄConnectionÖ®ºó Private Sub Connection1_ConnectComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) Disconnect Connection¹Ø±ÕÖ®ºó Private Sub Connection1_Disconnect(adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) ExecuteComplete Íê³ÉConnection.Execute»òCommand.Execute֮ʱ Private Sub Connection1_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection) InfoMessage Ò»¸öError¶ÔÏó±»Ìí¼Óµ½ADODB.Connectio.Error¼¯ºÏ֮ʱ Private Sub Connection1_InfoMessage(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) RollbackTransComplete RollbackTrans·½·¨Ö´ÐÐÖ®ºó Private Sub Connection1_RollbackTransComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) WillConnect ¼´½«µ÷ÓÃConnection.Open·½·¨Ö®Ê± Private Sub Connection1_WillConnect(ConnectionString As String, UserID As String, Password As String, Options As Long, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) WillExecute ¼´½«µ÷ÓÃConnection.Execute»òCommand.Execute·½·¨Ö®Ê± Private Sub Connection1_WillExecute(Source As String, CursorType As ADODB.CursorTypeEnum, LockType As ADODB.LockTypeEnum, Options As Long, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection) ×¢£ºÆäÖеÄadStatus²ÎÊýËùÓõ½µÄ³£ÊýµÄÃû³ÆºÍº¬ÒåÏê¼ûadStatusËùÓõij£Êý ³£Êý IsolationLevel³£Êý ³£Êý º¬Òå adXactCursorStability Ö»ÔÊÐí¶ÁÆäËûÊÂÎñÒÑÌá½»µÄ¸Ä±ä£¨Ä¬ÈÏÖµ£© adXactBrowse ÔÊÐí¶ÁÆäËûÊÂÎñδÌá½»µÄ¸Ä±ä adXactChaos ±¾ÊÂÎñ²»»á¸²¸ÇÆäËûλÓÚ¸ü¸ß¸ôÀë³Ì¶ÈµÄÊÂÎñËù×öµÄ¸Ä±ä adXactIsolated ËùÓÐÊÂÎñÏ໥¶ÀÁ¢ adXactReadCommitted µÈͬÓÚadXactCursorStability adXactReadUncommitted µÈͬÓÚadXactBrowse adXactRepeatableRead ½ûÖ¹¶ÁÆäËûÊÂÎñµÄ¸Ä±ä adXactSerializable µÈͬÓÚadXactIsolated adXactUnspecified ²»ÄÜÈ·¶¨ÌṩÕßµÄÊÂÎñ¸ôÀë³Ì¶È Mode³£Êý ³£Êý º¬Òå adModeUnknown δָ¶¨Êý¾ÝÔ´µÄÁ¬½ÓÐí¿ÉȨ£¨Ä¬ÈÏÖµ£© adModeRead Á¬½ÓÊÇÖ»¶ÁµÄ adModeReadWrite Á¬½ÓÊǿɶÁдµÄ adModeShareDenyNone ²»¾Ü¾øÆäËûÓû§µÄ¶Áд·ÃÎÊ(Jet OLE DB ProviderµÄĬÈÏÖµ) adModeShareDenyRead ¾Ü¾øÆäËûÓû§´ò¿ªµ½Êý¾ÝÔ´µÄ¶ÁÁ¬½Ó adModeShareDenyWrite ¾Ü¾øÆäËûÓû§´ò¿ªµ½Êý¾ÝÔ´µÄдÁ¬½Ó adModeShareExclusive ÒÔ¶ÀÕ¼·½Ê½´ò¿ªÊý¾ÝÔ´ adModeWrite Á¬½ÓÊÇֻдµÄ State³£Êý ³£Êý º¬Òå adStateClosed Connection(»òÆäËû¶ÔÏó)ÊǹرյÄ(ĬÈÏÖµ) adStateConnecting ÕýÔÚÁ¬½ÓÊý¾ÝÔ´µÄ״̬ adStateExecuting Connection»òCommand¶ÔÏóµÄExecute·½·¨Òѱ»µ÷Óà adStateFetching ·µ»ØÐÐ(row)µ½Recordset¶ÔÏó adStateOpen Connection(»òÆäËû¶ÔÏó)ÊÇ´ò¿ªµÄ(»î¶¯µÄ) Execute·½·¨ÖÐlngOption²ÎÊýÓõ½µÄ³£Êý CommandÀàÐͳ£Êý º¬Òå adCmdUnknown CommandÀàÐÍ䶨£¨Ä¬ÈÏÖµ£©£¬ÓÉÊý¾ÝÌṩÕßÈ¥ÅбðCommandÓï·¨ adCmdFile CommandÊǺͶÔÏóÀàÐÍÏàÓ¦µÄÎļþÃû³Æ adCmdStoredProc CommandÊÇ´æ´¢¹ý³ÌÃû³Æ adCmdTable CommandÊÇÄܲúÉúÄÚ²¿SELECT * FROM TableName²éѯµÄ±íÃû³Æ adCmdTableDirect CommandÊÇÄÜÖ±½Ó´Ó±íÖлñÈ¡ÐÐÄÚÈݵıíÃû³Æ adCmdText CommandÊÇÒ»ÌõSQLÓï¾ä ADODBʼþ´¦Àí×Ó¹ý³Ì²ÎÊýadStatusËùÓõij£Êý ³£Êý º¬Òå adStatusCancel ²Ù×÷±»Óû§È¡Ïû adStatusCnatDeny ²Ù×÷²»ÄܾܾøÆäËûÓû§¶ÔÊý¾ÝÔ´µÄ·ÃÎÊ adStatusErrorsOccurred ²Ù×÷µ¼Ö´íÎó²¢ÒÑË͵½Errors¼¯ºÏÖÐ adStatusOK ²Ù×÷³É¹¦ adStatusUnWantedEvent ²Ù×÷¹ý³ÌÖÐÒ»¸öδԤÁϵ½µÄʼþ±»¼¤»î
--------------------------------------------------------------------------------
Ïà¹ØÎÄÕÂ
SQL SERVER»ù±¾¸ÅÄîѧϰӡÏó 2004-1-1 21:23:13
ERwin--¼ò»¯µÄÊý¾Ý¿âÉè¼Æ¹¤¾ß 2003-12-15 12:41:40
ÔÚºêÌõ¼þÖÐÅжϴ°Ìåβ¼Ç¼ 2003-11-20 16:25:48
Á˽â Microsoft Access °²È«ÐÔ 2003-11-13 11:21:08
²»µ±±àдSQLÓï¾äµ¼ÖÂϵͳ²»°²È« 2003-11-13 10:55:26
ʹÓà Jet UserRoster ¼ì²éÊÇ˵Ǽµ½Êý¾Ý¿âÖÐ 2003-10-18 9:54:42
´´½¨ÍêÃÀ±¨±í 2003-10-17 19:37:17
SQL SERVER ÓëACCESS¡¢EXCELµÄÊý¾Ýת»» 2003-10-17 19:12:00
¶¯Ì¬Ìí¼Ó»òɾ³ýÒýÓà 2003-10-17 19:01:02
MS Jet SQL for Access 2000Öм¶Æª(IV) 2003-10-17 18:52:20
MS Jet SQL for Access 2000Öм¶Æª (III) 2003-10-17 18:51:47
MS Jet SQL for Access 2000Öм¶Æª (II) 2003-10-17 18:51:01
MS Jet SQL for Access 2000Öм¶Æª (I) 2003-10-17 18:47:38
ʹÓÃADOÁ¬½Óµ½·À»ðǽºóµÄSQL Server 2003-10-17 18:43:57
ADOÁ¬½ÓÊý¾Ý¿â×Ö·û´®´óÈ« 2003-10-17 18:40:47
VBAÖгõʼ»¯ADOÁ¬½ÓµÄ¼¸ÖÖ·½·¨ 2003-10-14 8:46:43
ÓÃADOÀ´Ñ¹ËõÊý¾Ý¿â 2003-10-14 8:46:12
ADOÈý´ó¶ÔÏóµÄÊôÐÔ¡¢·½·¨¡¢Ê¼þ¼°³£Êý£¨¶þ£© 2003-10-14 8:45:33
ADOÈý´ó¶ÔÏóµÄÊôÐÔ¡¢·½·¨¡¢Ê¼þ¼°³£Êý£¨Èý£© 2003-10-14 8:44:20
ÈçºÎÕï¶Ï/ÐÞ¸´Ëð»µµÄ Jet 4.0 Êý¾Ý¿â 2003-10-14 8:31:26
ÌáÉýÇ°ºǫ́ģʽ³ÌÐòµÄËÙ¶È 2003-10-10 10:17:08
»ñÈ¡Ö¸¶¨±íËùÓÐ×Ö¶ÎÃûµÄº¯Êý 2003-10-6 16:44:38
Ò»¸ö¼òµ¥µÄAdoÓ÷¨Ê¾Àý 2003-10-6 16:24:38
Êý¾Ý¿âÓ¦ÓóÌÐòÐè×¢ÒâµÄÎÊÌâ 2003-10-6 11:11:06
|