| <SCRIPT language=VBScript RUNAT=server>
Dim ConnectionString
' ******************************************************
' Application 変数による DB接続
' ******************************************************
Function DBConnectByEnv( DBType, Connection )
DBConnectByEnv = _
DBConnect( _
DBType, _
Connection, _
Application("SERVER"), _
Application("DB"), _
Application("USER"), _
Application("PASS") _
)
End Function
' ******************************************************
' DB接続
' ******************************************************
Function DBConnect( _
DBType, _
Connection, _
strTarget, _
strDB, _
strUser, _
strPass _
)
if IsEmpty( Connection ) then
Set Connection = Server.CreateObject( "ADODB.Connection" )
end if
Select Case DBType
Case "Excel"
ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strTarget & ";" & _
"Extended Properties=""Excel 8.0;IMEX=1;"""
Case "MDB"
ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strTarget & ";"
Case "MySQL"
ConnectionString = _
"Provider=MSDASQL" & _
";DSN=" & strTarget & _
";DATABASE=" & strDB & _
";UID=" & strUser & _
";PWD=" & strPass & _
";"
Case "SQLServer"
ConnectionString = _
"Provider=SQLOLEDB;" & _
"Data Source=" & strTarget & ";" & _
"Initial Catalog=" & strDB & ";" & _
"User ID=" & strUser & ";" & _
"Password=" & strPass & ";"
End Select
DBConnect = True
on error resume next
Connection.Open ConnectionString
if Err.Number <> 0 then
Response.Write "DB に接続できません "
Response.Write Err.Description
DBConnect = False
end if
on error goto 0
End Function
' ******************************************************
' DB終了処理(接続を閉じる)
' ******************************************************
Function DBClose( _
CnRs _
)
On Error Resume Next
If CnRs.State >= 1 Then
CnRs.Close
End If
On Error Goto 0
DBClose = True
End Function
' ******************************************************
' DB読込み
' 【戻り値】: True(データ有り),False(データ無し)
' ******************************************************
Function DBGet( _
Connection, _
Record, _
SqlQuery, _
bUpadateFlg _
)
if IsEmpty( Record ) then
Set Record = Server.CreateObject( "ADODB.Recordset" )
end if
' 閉じていない時は閉じる
If Record.State >= 1 Then
Record.Close
End If
' 更新処理に使用する場合は、レコード単位の共有的ロック
If bUpadateFlg Then
Record.LockType = 3
End If
' レコードセット作成
On Error Resume Next
Record.Open SqlQuery, Connection
If Err.Number <> 0 then
Response.Write Err.Description
End If
If Record.EOF Then
DBGet = False
Else
DBGet = True
End If
On Error Goto 0
End Function
' ******************************************************
' EOF
' 【戻り値】: True(EOF),False(データ有り)
' ******************************************************
Function DBEof( Record )
Dim bRet
On Error Resume Next
bRet = Record.EOF
If Err.Number <> 0 then
Response.Write "DBEof でエラー : " & Err.Description
DBEof = True
Exit Function
End If
On Error Goto 0
DBEof = bRet
End Function
</SCRIPT>
| |