|
分類:[VB.NET]
すいません。下記のVB.NETで作成したプログラムでストアドを実行したいのですが、さっぱりです。。多少関係なさそうな所は省きましたが、PGの内容の説明とストアドを指定している所、ご教授願えますでしょうか。
'===================================================================================================
' モジュール名称 : StoredProcedure実行バッチ(SPExecute)
' モジュール概要 : ストアドプロシージャを実行するバッチ
'===================================================================================================
Imports AAAA
Imports AAAA.common
Imports AAAA.DB.Business
Imports AAAA.Batch.DB.System
Imports AAAA.Batch.DB.BUSINESS
Imports AAAA.Batch.Common
Imports System.Collections.Specialized
Imports System.Data.SqlClient
Imports AAAA.DB.System
Imports System
Imports System.Text.RegularExpressions
Namespace Batch.DWH
Module SPExecute
Private Const c_MESSAGE_OF_ERROR_ARGS As String = _
"usage: SPExecute [SP名] ([モード])"
Private Const c_MESSAGE_OF_ERROR_SPNAME As String = _
"SP名がConfigファイルに設定されていません。"
Private Const c_MESSAGE_OF_ERROR_SP_EXECUTE As String = _
"SP実行時にエラーが発生しました。"
Private Const c_MESSAGE_OF_ERROR_SYSTEM As String = _
"システムエラーが発生しました。"
Private Const c_MESSAGE_OF_NORMAL_EXIT As String = _
"SP実行バッチが正常に終了しました。"
Private Const c_MESSAGE_OF_EXIT As String = _
"SP実行バッチが終了しました。"
Private Const c_NORMAL_CD As Integer = 0
Private Const c_ERROR_CD As Integer = -1
Sub Main(ByVal args() As String)
Dim objBatchProvider As clsBatchSQLServerProvider = Nothing 'バッチ用DB接続
Dim objProvider As clsSQLServerProvider = Nothing 'DB接続
Dim objConn As SqlConnection = Nothing 'SQLコネクション
Dim objExecuteSP As clsExecuteSP = Nothing 'SP実行Class
Dim hasParam As Hashtable = Nothing 'SP実行パラメータ
Dim strSPName As String = "" 'SP名
Dim strSPNameTemp As String = "" 'SP名取得退避用
Dim strSPParameters As String = "" 'SP実行引数
Dim strErrorMessage As String = ""
Dim nRtnCD As Integer = c_ERROR_CD
Try
If args.Length < 1 Or args.Length > 2 Then
Console.WriteLine(c_MESSAGE_OF_ERROR_ARGS)
Throw New ApplicationException(c_MESSAGE_OF_ERROR_ARGS)
End If
Dim strSPExecuteName As String = args(0).ToString
'Batch.configからSP名+引数を取得
strSPNameTemp = clsBatchCommon.getBatchConfigValue(strSPExecuteName)
If (strSPNameTemp.Equals("")) Then
Console.WriteLine(c_MESSAGE_OF_ERROR_SPNAME)
Throw New ApplicationException(c_MESSAGE_OF_ERROR_SPNAME)
End If
'バッチコンフィグから引数取得
strSPName = Regex.Match(strSPNameTemp, "^(\w+)\s").Value
strSPParameters = strSPNameTemp.Replace(strSPName, "")
'DB接続開始
objBatchProvider = New clsBatchSQLServerProvider
objProvider = objBatchProvider.getObjSQLProvider()
objConn = objProvider.GetConnection
objProvider.SetTransaction(objProvider.GetTransaction)
'トランザクション開始
objProvider.BeginTransaction()
'SP実行
objExecuteSP = New clsExecuteSP(objProvider)
objExecuteSP.Execute(strSPName, strSPParameters)
'パラメータ確認
hasParam = objExecuteSP.getOutputParameter
'戻り値の確認
If Not (hasParam(objExecuteSP.c_PARAM_OF_RTNCD) Is Nothing) Then
nRtnCD = hasParam(objExecuteSP.c_PARAM_OF_RTNCD)
If (hasParam(objExecuteSP.c_PARAM_OF_MESSAGE) Is Nothing) Then
strErrorMessage = c_MESSAGE_OF_ERROR_SP_EXECUTE
Else
If Not (hasParam(objExecuteSP.c_PARAM_OF_MESSAGE) Is DBNull.Value) Then
strErrorMessage = hasParam(objExecuteSP.c_PARAM_OF_MESSAGE)
Console.WriteLine(strErrorMessage)
End If
End If
Console.WriteLine(strErrorMessage)
If (nRtnCD = c_ERROR_CD) Then
Throw New ApplicationException
Else
Console.WriteLine(c_MESSAGE_OF_NORMAL_EXIT)
End If
Else
Console.WriteLine(c_MESSAGE_OF_EXIT)
End If
'トランザクションクローズ
objProvider.CommitTransaction()
Catch ex As ApplicationException
'アプリケーションエラーの場合は
If Not objProvider Is Nothing Then
objProvider.CommitTransaction()
End If
Catch ex As Exception
clsLogUtil.OutputErrorLog("SPExecute", "Main", ex)
Console.WriteLine(c_MESSAGE_OF_ERROR_SYSTEM)
If Not objProvider Is Nothing Then
objProvider.RollbackTransaction()
End If
Finally
'SQLServer切断
If Not objProvider Is Nothing Then
objProvider.CloseConnection(objConn)
End If
Environment.Exit(nRtnCD)
End Try
End Sub
End Module
End Namespace
|