-2

我遇到错误“System.ArgumentException:该值不能为空、字符串或空。”
在线路代码处

Public Sub New(ByVal databaseName As String)
            **db = New Database(databaseName)**
End Sub

导致源文件为“C:\Company\Main\Source\DataLayer\Object2.vb”的错误请找到屏幕截图。

请问你能帮忙吗?

任务说明
我正在尝试从上述根文件的以下函数中执行“db_StoredProcedue”。C:\Company\Main\Source\Project\App_Code\Application\ResultDataset.vb

    Imports System.Web.UI
    Imports System.Data
    Imports System.IO
    Imports Company.Web.TMSuite.Workflow
    Namespace Company.Web.TMSuite
    Public Class ResultDataset
        Inherits BasePage
        Public Shared Function GetResultsDataset() As DataSet
            Dim Obj1 As New Workflow(BasePage.DatabaseName)

            Dim ds As New DataSet

            ds = Obj1.GetResultDataset()

            Return ds

        End Function

    End Class

End Namespace  

Obj1 文件位于 C:\Company\Main\Source\Workflow\Object1.vb

Imports System.Globalization
Imports Company.Web.TMSuite.DataAccess
Imports Company.Web.TMSuite.TMSuiteComponents
Public Class Workflow
    Private objResultsData As ResultsData  

Public Sub New(ByVal databaseName As String)
    objMetricsData = New MetricsData(databaseName)
End Sub

Public Function Obj2() As DataSet
        Return objResultssData.Obj2()
    End Function
End Class  

Obj2 文件位于 C:\Company\Main\Source\DataLayer\Object2.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Globalization
Imports System.Web
Imports System.Data.Common
Imports Company.FoundationLibrary.Data
Imports Company.FoundationLibrary.ExceptionHandling
Imports Company.Web.TMSuite.DataAccess.ExceptionPolicies
Imports System.Data.SqlClient

Public Class ResultsData
    Inherits BaseData

    Public Sub New(ByVal databaseName As String)
        db = New Database(databaseName)  //Error Throughing at this line as -> ""System.ArgumentException: The value can not be null or string or empty.""
    End Sub

  Public Function Obj2() As DataSet
        Dim errorMessage As String = Nothing
        Dim ds As New DataSet
        Dim cmd As DbCommand

        ds.Locale = CultureInfo.InvariantCulture
        Try
            cmd = db.GetStoredProcCommand("db_StoredProcedue")

            db.AddOutParameter(cmd, "@pErrorMessage", DbType.String, ErrorMessageSize)

            ds = db.ExecuteDataSet(cmd)

            If Not IsDBNull(db.GetParameterValue(cmd, "@pErrorMessage")) Then
                errorMessage = db.GetParameterValue(cmd, "@pErrorMessage")
            End If

        Catch ex As Exception

            Dim blnRethrow As Boolean = ExceptionPolicy.HandleException(ex, DataAccessExceptionPolicy)

            If blnRethrow Then
                Throw
            End If
        End Try

        Return ds

    End Function
End Class  

请让我知道,如果我必须发布额外的代码来解决这个问题。

4

2 回答 2

0

导致的问题是:

对于 C:\Company\Main\Source\Project\Forms\webpage.aspx.vb 和 pages.vb 中的方法“从 basepage.databasename 属性访问数据库

但是,我们无法从 basepage.databasename 属性
C:\Company\Main\Source\Project\App_Code\Application\ResultDataset.vb 访问数据库

于 2012-07-17T15:08:49.230 回答
0

我认为您的代码示例中有一些拼写错误,但根据我正在阅读的内容,我认为您未能通过 Workflow 类中的调用将数据库名称传递给 objResults 类的构造函数。它作为 null 隐式提供,这会引发异常。

我基于这样的推论,即“Private objResultsData as ResultsData”确实应该被声明为“Private objResultsData as objResults” ,或者您的 objResults 类应该被声明为“ResultsData”。如果我误解了代码,请接受我的道歉。

编辑:根据 OP 反馈,Workflow 类需要一个构造函数和成员字段来包含数据库名称,然后可用于显式初始化 ResultsData 类并消除问题。希望有帮助!

Imports System.Globalization
Imports Company.Web.TMSuite.DataAccess
Imports Company.Web.TMSuite.TMSuiteComponents
Public Class Workflow
    Private databaseName as String
    Private objResultsData As ResultsData
    Public Sub New (DatabaseName as String)
        Me.databaseName = DatabaseName
    End Sub
    Public Function Obj2() As DataSet
        objResultsData = new ResultsData(Me.DatabaseName)
        Return objResultsData.Obj2() ' Alternate possibility is to pass the name as parm here
    End Function
End Class 

然后,您需要修改 Workflow 的实例化以在构造函数中包含数据库名称,从而将其沿链传递。需要注意的是,上面的代码未经测试,但应该为您说明相关点。

于 2012-07-17T13:46:55.583 回答