VB Function으로 DB연결 관련된 내용을 구성하여 쉽게 dB 접근및 Query 전송 하기
'------------------- DBConnection.asp
<!--METADATA type="typelib" FILE="C:\program Files\Common Files\System\ado\msado15.dll"-->
Dim Conn
Function OpenDB()
Dim SeverName, DatabaseName, strUserID, strUserPW
SeverName = "DBIP:port"
DatabaseName = "DBname"
strUserID = "DBUser"
strUserPW = "UserPW"
Conn.ConnectionString = "provider=SQLOLEDB;Data Source=" & SeverName & ";Initial Catalog=" & DatabaseName & ";User Id=" & DBUser& ";Password=" & strUserPW
Conn.ConnectionTimeout = 20
Conn.Open
Conn.BeginTrans()
End Function
Function CloseDB()
If Conn.Errors.Count > 0 Then
Conn.RollbackTrans()
Else
Conn.CommitTrans()
End If
If VarType(Conn) = vbString Then
If Conn.state Then
Conn.Close
End If
End If
End Function
Function QuerySend(strConn, strQuery)
Dim RecordSet
On Error Resume Next
Set RecordSet = Server.CreateObject("ADODB.RecordSet")
RecordSet.Open strSql, strConn, 0, 1
If RecordSet.bOF Or RecordSet.EOF Then
dbQuery = ""
Else
dbQuery = RecordSet.GetRows
End If
RecordSet.Close
Set RecordSet = Nothing
If Err.number <> 0 Then
Err.Clear
End If
End Function
' ----------------------------- end
<!-- #include virtual="DBConnection.asp" //-->
<%
Dim rTData, strQuery, rRow
Call OpenDB()
setQuery = "Select *from Table"
rTData = QuerySend(Conn, strQuery)
Dim IndexLow, indexColl, nLow, nColl
nLow = UBound(rTData, 2)
nColl = UBound(rTData, 1)
Call CloseDB()
if IsArray(rTData) Then
for indexLow = 0 To nLow
for indexColl = 0 To nColl
Response.Write(RS_Tdata(indexColl, indexLow)
NEXT
NEXT
End if
%>
댓글 없음:
댓글 쓰기