¾È±Ô °øºÎ¹æ

ACTIVE SERVER PAGE > Connection - Method

µî·ÏÀÏ : 2017-07-04 17:02 Á¶È¸¼ö : 53,156


 ¾È³çÇϼ¼¿ä...
Connection °³Ã¼ÀÇ ¼Ó¼º ´ëÇؼ­ °£´ÜÈ÷ ¾Ë¾Æº¸¼ÌÂÇ????
¿À´ÃÀº ÀÌ °³Ã¼ÀÇ ¸Þ¼Òµå´Â ¾î¶²°ÍµéÀÌ ÀÖ´ÂÁö¸¦ ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
 
  5.4.1 BeginTrans, CommitTrans, RollbackTrans ¸Þ¼Òµå
 
  À§ ¼¼°³ÀÇ ¸Þ¼Òµå¸¦ »ç¿ëÇÑ ¿¹Á¦ ÀÔ´Ï´Ù.
 
Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")	
	objCnn.BeginTrans
	
	strSql=" INSERT INTO BOARD(NUMBER,TITLE,CONTENT) VALUES(1,'¿¬½À','³»¿ëÀÔ´Ï´Ù.')"
	Set objRs = objCnn.Execute(strSql)

	If objCnn.Errors.Count > 0 Then    
        	objCnn.RollBackTrans 
        	objCnn.close
        	Set objCnn=Nothing
        	response.write  "Error Transection"
	Else
        	objCnn.CommitTrans 
        	objCnn.close
        	Set objCnn=Nothing
        	response.write "OK Transection"
	End If

	objCnn.close
	Set objCnn=Nothing



Æ®·£Á§¼Ç¿¡ ´ëÇÑ °³³äÀº ¾Ë°í °è½Ã¸®¶ó ¹Ï½À´Ï´Ù. Ȥ½Ã ¸ð¸£½Å´Ù¸é, MS_SQL °­ÁÂÂÊ¿¡

Transaction & Lock  ¸Þ´º¸¦ ¸ÕÀú º¸½ÅÈÄ¿¡ ¿À¼¼¿ë.

¿©±â¿¡¼­´Â Æ®·£Àè¼Ç¿¡ ´ëÇÑ ³»¿ëÀÌ ¾Æ´Ï¶ó Connection °³Ã¼¿¡ ¸Þ¼Òµå¿¡ ´ëÇÑ ³»¿ëÀ̱⠶§¹®ÀÌÁ®.

À§ÀÇ ¼Ò½º¸¦ º¸¸é, objCnn.BeginTrans ¶ó°í Çß½À´Ï´Ù. Áï, Æ®·£Àè¼ÇÀ» ½ÃÀÛÇÑ´Ù´Â ³»¿ëÀä.

ÀÌÈÄ¿¡ ³ª¿À´Â µðºñ Çڵ鸵Çϴ°Ϳ¡ ´ëÇؼ­´Â commitTrans,rollbackTrans¸¦ ¸¸³ª¾ß

µ¥ÀÌÅͼöÁ¤ÀÌ Á¾·áµÇ´Â°ÍÀ» ¶æÇÕ´Ï´Ù.

¾Æ½ÃÁ®???

À§ÀÇ ¿¹Á¦¿¡¼­´Â error Ä÷º¼ÇÀ» ÀÌ¿ëÇؼ­ rollbacktrans,commitTransÀ» ó¸®ÇÏ°Ô µÇ¾î ÀÖ½À´Ï´Ù.
 

	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")

	objCnn.BeginTrans

	strSql=" INSERT INTO BOARD(board_idx,TITLE,CONTENT) VALUES(1,'¿¬½À','³»¿ëÀÔ´Ï´Ù.')"
	Set objRs = objCnn.Execute(strSql)

	objCnn.RollbackTrans

	objCnn.close
	Set objCnn=Nothing



À§ÀÇ ¿¹Á¦´Â µ¥ÀÌÅ͸¦ ÀúÀåÇÑÈÄ ¹Ù·ç rollbackTrans À» ó¸®ÇÑ ¿¹ÀÔ´Ï´Ù.

µðºñ¿¡¼­ È®ÀÎÇØ º¸¸é, ÀúÀåÀÌ µÇÁö ¾Ê¾Ò°ÚÁö¿ä???

  5.4.2 Close ¸Þ¼Òµå
 
  ÀÌ ¸Þ¼­µå´Â ¿­·ÁÁø Connection °³Ã¼¿Í ±× ÇÏÀ§ °³Ã¼¸¦ ´Ý´Â ¸Þ¼Òµå ÀÔ´Ï´Ù.
 
  5.4.3 Execute ¸Þ¼Òµå
 
  °¡Àå ¸¹ÀÌ »ç¿ëÇÏ´Â ¸Þ¼Òµå Áß¿¡ ÇϳªÀÌÁö¿ä???
 

	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")

	strSql=" INSERT INTO BOARD(board_idx,TITLE,CONTENT) VALUES(1,'¿¬½À','³»¿ëÀÔ´Ï´Ù.')"

	Set objRs = objCnn.Execute(strSql)

	objCnn.close
	Set objCnn=Nothing


 
  À§¿Í ÇÔ²² »ç¿ë »ç¿ëÇϼÌÁö¿ä???
 
  ¿©±â±îÁö´Â ´Ù ¾Æ½Ã´Â ³»¿ëÀÌ´Ï, ³Ñ¾î°¡±â·ç Çϱ¸¿ä. ¿ì¸° ¿©±â¿¡¼­ ÇÑ´Ü°è ±íÀÌ µé¾î°¡ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
  ¸¸¾à ¿©·¯ºÐÀÌ ¿©±â¿¡¼­ SQL ¹®ÀåÀ» ÅëÇØ ¿µÇâÀ» ¹ÞÀº ·¹ÄÚµåÀÇ ¼ö¸¦ ¾Ë¾Æº¸°íÀÚ ÇÑ´Ù¸é
  ¾î¶»°Ô ÇϽðڽÀ´Ï±î???
 
  À¢ °©Àڱ⠷¹ÄÚµå ¼ö³Ä±¸¿ä???
 
  Execute ¸Þ¼Òµå¿¡¼­ ÀÌ·¯ÇÑ Á¤º¸µµ »Ì¾Æº¼¼ö ÀÖ½À´Ï´Ù. ±×¸®±¸, ¿©·¯°¡Áö ¸Å°³º¯¼ö¸¦ ÅëÇØ ¼öÇàµÇ´Â
 
  commandText(¿©±â¿¡¼­´Â strSql)°¡ SQL ¹®ÀåÀÎÁö,Å×À̺í¸íÀÎÁö, ÀúÀå ÇÁ·Î½ÃÁ®ÀÎÁö¸¦ ÁöÁ¤ÇÒ¼öµµ ÀÖ½À´Ï´Ù.
 
  ±×·³, ÀÏ´Ü Execute ¸Þ¼ÒµåÀÇ ±¸¹®À» ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
 
 
    
	1) RecordsetÀÌ ¹ÝȯµÉ°æ¿ì
	   Set objCnn = Server.CreateObject("ADODB.Connection")
	   :
	   SET objRs=objCnn.Execute(CommandText As String,[RecordsAffected As Long],[Options As Enum])
	2) Recordset °³Ã¼°¡ ¹ÝȯµÇÁö ¾ÊÀ» °æ¿ì
	   Set objCnn = Server.CreateObject("ADODB.Connection")
	   :
	   Connection.Execute CommandText As String,[RecordsAffected As Long],[Options As Enum]
	
      

À§¿Í °°Àº ±¸¹®À» »ç¿ëÇÕ´Ï´Ù.

1. CommandText : ¼öÇàÇÒ ¸í·ÉÀ» ±â¼úÇÏ´Â ¸Å°³º¯¼öÀÔ´Ï´Ù.SQL ¹®Àå,Å×À̺í¸í,ÀúÀå ÇÁ·Î½ÃÁ®µîÀ» ±â¼úÇÕ´Ï´Ù.
2. RecordsAffected : Execute ¸Þ¼Òµå¿¡ ÀÇÇؼ­ ¿µÇâÀ» ¹ÞÀº ·¹ÄÚµåÀÇ °¹¼ö¸¦ ¹ÝȯÇÕ´Ï´Ù.
3. Options : Provider°¡ CommandText¸¦ ¾î¶»°Ô ¼öÇàÇÒÁö¸¦ °áÁ¤ÇÏ´Â ¹æ¹ýÀ» ÁöÁ¤ÇÏ´Â °ªÀÔ´Ï´Ù.

Options ¸Å°³º¯¼ö¿¡´Â ¾Æ·¡ Ç¥ÁßÀÇ ÇϳªÀÇ °ªÀ» °¡Áú¼ö ÀÖ½À´Ï´Ù.
 
¼Ó ¼º ¼³ ¸í
adCmdText
adCmdTable
adCmdTableDirect
adCmdStoredProc
adCmdUnknown
adAsyncExecute
adAsyncFetch
CommandTextÀÇ °ªÀ» SQL ¹®ÀåÀ¸·Î ó¸®ÇÑ´Ù.
CommandTextÀÇ °ªÀ» Å×ÀÌºí ¸íÀ¸·Î ÇÏ´Â sql ¹®ÀåÀ» ¸¸µé¾î ó¸®ÇÑ´Ù.
CommandTextÀÇ °ªÀ» Å×À̺í¸íÀ¸·Î ó¸®ÇÑ´Ù.
CommandTextÀÇ °ªÀ» ÀúÀå ÇÁ·Î½ÃÁ®·Î ó¸®ÇÑ´Ù.
¸í·ÉÀÇ Çü½ÄÀ» ¾Ë¼ö ¾øÀ½À¸·Î ó¸®ÇÑ´Ù.
¸í·ÉÀ» ºñµ¿±âÀûÀ¸·Î ¼öÇàÇÑ´Ù.
CasheSize ¼Ó¼º¿¡ ÁöÁ¤µÈ ¼ö ¸¸Å­ÀÇ ·¹Äڵ徿 ºñµ¿±âÀûÀ¸·Î ó¸®ÇÑ´Ù.
  


±×·³, °£´ÜÇÏ°Ô ¸î°¡Áö ¿¹Á¦¸¦ º¸¸é¼­ Å×½ºÆ® Çغ¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
 

	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")

	strSql=" INSERT INTO BOARD(board_idx,TITLE,CONTENT) VALUES(1,'¿¬½À','³»¿ëÀÔ´Ï´Ù.')"

	Set objRs = objCnn.Execute(strSql,aa)

	response.write aa
	objCnn.close
	Set objCnn=Nothing



À§ÀÇ ¿¹Á¦¸¦ º¸¸é

Set objRs = objCnn.Execute(strSql,aa)

aa ¸Å°³º¯¼ö´Â sql¹®ÀåÀ» ¼öÇàÇÑÈÄ ¿µÇâÀ» ¹ÞÀº ·¹ÄÚµåÀÇ ¼ö¸¦ ¹ÝȯÇÏ´Â º¯¼ö°¡ µË´Ï´Ù.

À§ÀÇ ¿¹Á¦¿¡¼­´Â ·¹Äڵ尡 Çϳª ¿µÇ⠹޾ұ⠶§¹®¿¡ '1'À̶õ °ªÀÌ Ãâ·ÂÀÌ µË´Ï´Ù.

¾Æ·¡ÀÇ ¿¹Á¦´Â Options ¸Å°³º¯¼ö±îÁö »ç¿ëÇÑ ¿¹ ÀÔ´Ï´Ù.
 

	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")

	Set objRs = objCnn.Execute("test 1",aa,adCmdStoredProc)

	response.write aa&"<br>"
	response.write objRs("title")
	objCnn.close
	Set objCnn=Nothing



ÀúÀå ÇÁ·Î½ÃÁ® ³»¿ë....
 

	CREATE PROCEDURE test (@class varchar(50)) AS
		select board_idx,title from board where board_idx=@class
	



test¶õ À̸§À¸·Î ÀúÀåÇÁ·Î½ÃÁ®¸¦ Çϳª ¸¸µé¾ú½À´Ï´Ù.

À§ÀÇ °æ¿ì adCmdStoredProc ´Â ÀúÀåÇÁ·Î½ÃÁ®¸¦ ¶æÇÏ°Ô µÇ¹Ç·Î ÀúÀåÇÁ·Î½ÃÁ®¿¡¼­ Àоî¿Í ½ÇÇàÇÏ°Ô µË´Ï´Ù.
¿µÇâÀ» ¹ÞÀº ·¹ÄÚµå´Â ¾ø±â¶§¹®¿¡ aa º¯¼ö´Â -1ÀÌ ¹ÝȯµÇ±¸ title¿¡´Â °á°ú°¡ ³ª¿À´Â°ÍÀ» ¾Ë¼ö ÀÖ½À´Ï´Ù.

  5.4.4. OpenSchema ¸Þ¼Òµå
 
  OpenSchema ¸Þ¼­µå´Â ¼­¹ö¿¡ ÀÖ´Â µ¥ÀÌÅͺ£À̽ºÀÇ Á¤º¸ ¶Ç´Â Å×À̺íÀÇ ÇʵåÀÇ Á¤º¸¿Í °°Àº µ¥ÀÌÅÍ ¼Ò½ºÀÇ
  Á¤º¸¸¦ ¹ÝȯÇÏ´Â ¸Þ¼­µå ÀÔ´Ï´Ù.
 
  OpenSchema ±¸¹®À» »ìÆ캸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
 

  	set Rs=objCnn.OpenSchema(QueryType,Criteria,SchemaID)
  	
  	
	
	'---- SchemaEnum Values ----
	Const adSchemaProviderSpecific = -1
	Const adSchemaAsserts = 0
	Const adSchemaCatalogs = 1
	Const adSchemaCharacterSets = 2
	Const adSchemaCollations = 3
	Const adSchemaColumns = 4
	Const adSchemaCheckConstraints = 5
	Const adSchemaConstraintColumnUsage = 6
	Const adSchemaConstraintTableUsage = 7
	Const adSchemaKeyColumnUsage = 8
	Const adSchemaReferentialConstraints = 9
	Const adSchemaTableConstraints = 10
	Const adSchemaColumnsDomainUsage = 11
	Const adSchemaIndexes = 12
	Const adSchemaColumnPrivileges = 13
	Const adSchemaTablePrivileges = 14
	Const adSchemaUsagePrivileges = 15
	Const adSchemaProcedures = 16
	Const adSchemaSchemata = 17
	Const adSchemaSQLLanguages = 18
	Const adSchemaStatistics = 19
	Const adSchemaTables = 20
	Const adSchemaTranslations = 21
	Const adSchemaProviderTypes = 22
	Const adSchemaViews = 23
	Const adSchemaViewColumnUsage = 24
	Const adSchemaViewTableUsage = 25
	Const adSchemaProcedureParameters = 26
	Const adSchemaForeignKeys = 27
	Const adSchemaPrimaryKeys = 28
	Const adSchemaProcedureColumns = 29
	Const adSchemaDBInfoKeywords = 30
	Const adSchemaDBInfoLiterals = 31
	Const adSchemaCubes = 32
	Const adSchemaDimensions = 33
	Const adSchemaHierarchies = 34
	Const adSchemaLevels = 35
	Const adSchemaMeasures = 36
	Const adSchemaProperties = 37
	Const adSchemaMembers = 38
	Const adSchemaTrustees = 39
	
	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")
	
	Set objRs = objCnn.OpenSchema(adSchemaTables)

	do until objRs.eof
    		response.write objRs("TABLE_CATALOG")&":"&objRs("TABLE_SCHEMA")&":"
    					&objRs("TABLE_NAME")&":"&objRs("TABLE_TYPE")&"<BR>"
	objRs.movenext    
	loop



À§ÀÇ ¿¹Á¦´Â OpenSchema ¸Þ¼ÒµåÀÇ QueryTypeÀÌ adSchemaTables ÀÎ °ª(Criteria)µéÀ» »Ì¾Æ ¿Â°ÍÀÔ´Ï´Ù.

adSchemaTables QueryTypeÀ» ÀÌ¿ëÇؼ­ »Ì¾Æ¿Ã¼ö ÀÖ´Â °ªµéÀº 4°¡Áö°¡ ÀÖ½À´Ï´Ù.

TABLE_CATALOG -> µ¥ÀÌŸº£À̽º À̸§
TABLE_SCHEMA  -> Å×ÀÌºí ½ºÅ°¸¶ À̸§
TABLE_NAME    -> Å×À̺í À̸§
TABLE_TYPE    -> Å×À̺í ŸÀÔ


QueryType ÀÇ Á¾·ùÀÇ À§ ¼Ò½º¿¡¼­ ¼±¾ðÇÑ°Í°ú °°ÀÌ 39°¡Áö³ª µÇ´Â±º¿ä.
°¢±â ´Ù¸¥ QueryType º°·Î »Ì¾Æ¿Ã¼ö ÀÖ´Â Criteria °ªµµ ¸ðµÎ Ʋ¸³´Ï´Ù.
(°øºÎÇÒ°Ô ³Ê¹« ¸¹±º¿ä)
 

	Const adSchemaTables = 20
	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")

	Set objRs = objCnn.OpenSchema(adSchemaTables)

	do until objRs.eof
    		if objRs("table_type")="TABLE" THEN
    			response.write objRs("TABLE_NAME")&"<BR>"
    		end if
	objRs.movenext    
	loop

	objCnn.close



¸¸¾à »ç¿ëÀÚ°¡ ¸¸µç Å×À̺í À̸§¸¸À» °¡Áö°í ¿À°í ½Í´Ù¸é À§Ã³·³ »ç¿ëÇصµ µË´Ï´Ù.

±×·¯³ª, ¾Æ·¡Ã³·³ Criteria °ªÀ» ³Ö¾î¼­ °¡Áö°í ¿À¸é ´õ ÆíÇÏ°ÚÁö¿ä?
 

	Const adSchemaTables = 20

	Set objCnn = Server.CreateObject("ADODB.Connection")
	objCnn.Open ("Provider=SQLOLEDB;User ID=sa;Password=;Initial Catalog=test;Data Source=MOBBIE-ANKYU")

	Set objRs = objCnn.OpenSchema(adSchemaTables,table_name)

	do until objRs.eof
       		response.write objRs("TABLE_NAME")&"<BR>"
	objRs.movenext    
	loop

	objCnn.close



¾î¶°¼¼¿©. Á»´õ °£´ÜÇØ Á³Áö¿ä????

ÇÒ°Ô ¾ÆÁ÷µµ ³Ê¹« ¸¹Áö¸¸, OpenSchema ¸Þ¼Òµå´Â ¿©±â¿¡¼­ Á¢¾î¾ß ÇÒ°Í °°³×¿ä....
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.