1

我有一个提供 AS400 数据的网络服务。该网络服务有一个固定的连接字符串,我希望将其设为动态。请参见下面的代码:

    Public Function GetData(sql As String) As DataTable

            Dim _data As DataTable

            Try

                Dim s As String = "Provider=IBMDA400"

                s &= ";Data Source=" & "x.x.x.x"
                s &= ";User Id=" & "USER"
                s &= ";Password=" & "PASS"
                s &= ";Default Collection=" & "AAABBB"

                con = New OleDbConnection(s)

                Dim cmd As New OleDbCommand

                With cmd
                    .Connection = con
                    .CommandType = CommandType.Text
                    .CommandText = sql
                End With

                Dim dap As New OleDbDataAdapter(cmd)

                con.Open()

                Dim dat As New DataSet

                dap.Fill(dat)

                con.Close()
                con.Dispose()

                _data = dat.Tables(0)

            Catch ex As Exception

                _data = New DataTable

            End Try

            Return _data

        End Function

使用上述内容的示例 Web 服务功能:

<WebMethod()> _
        Public Function GetPicklistLines(picklist As String) As List(Of PicklistLine)

            Dim lines As New List(Of PicklistLine)
            Dim line As PicklistLine

            sql = "select " & _
                                    "OLPLNO,OLPLLI,OLORNO,OLLINE,OLPRDC,OLDESC,OLOQTS,OLCQTS,OLUNIT,OLORDS,PGDRNR, AAV01, AAV02, NAV03 " & _
                                    "from SRBSOL " & _
                                    "left outer join SRBPRG on PGPRDC=OLPRDC " & _
                                    "left outer join Z2OOCFGF on F0ERNC=OLORNO and F0A2NB=OLLINE " & _
                                    "where OLPLNO=" & picklist & " and OLSTAT <>' D'"

            data = GetData(sql)

            ' TODO: insert ROW 0 to set active:
            sql = "insert " & _
                    "into SRBSOL " & _
                    "(OLPLNO, OLPLLI) " & _
                    "values " & _
                    "(" & picklist & "," & 0 & ") " & _
                    "where OLPLNO=" & picklist & " and OLSTAT <>' D'"

            For Each dr As DataRow In data.Rows

                ' TODO: get reported quantity:
                sql = "select " & _
                        "RCBAQT " & _
                        "from Z2OOREXC " & _
                        "where RCPLNO='" & picklist & "' and RCPLLI='" & dr("OLPLLI") & "'"

                line = New PicklistLine

                With line
                    .PicklistNumber = picklist
                    .OrderNumber = IIf(TypeOf (dr("OLORNO")) Is DBNull, "", dr("OLORNO"))
                    .PicklistLinenumber = IIf(TypeOf (dr("OLPLLI")) Is DBNull, "", dr("OLPLLI"))
                    .Item = IIf(TypeOf (dr("OLPRDC")) Is DBNull, "", dr("OLPRDC"))
                    .ItemDescription = IIf(TypeOf (dr("OLDESC")) Is DBNull, "", dr("OLDESC"))
                    .InnerColor = IIf(TypeOf (dr("AAV01")) Is DBNull, "", dr("AAV01"))
                    .OuterColor = IIf(TypeOf (dr("AAV02")) Is DBNull, "", dr("AAV02"))
                    .Length = IIf(TypeOf (dr("NAV03")) Is DBNull, "", dr("NAV03"))
                    .Unit = IIf(TypeOf (dr("OLUNIT")) Is DBNull, "", dr("OLUNIT"))
                    .Quantity = IIf(TypeOf (dr("OLCQTS")) Is DBNull, "", CInt(dr("OLCQTS")))
                    .Needed = IIf(TypeOf (dr("OLOQTS")) Is DBNull, "", CInt(dr("OLOQTS")))
                End With

                lines.Add(line)

            Next

            Return lines

        End Function

上面的函数被 jquery 调用:

function GetAllPicklists() {
    $('#page_overview_search').addClass('ui-disabled');
    $("#Picklists").html('');
    //$("#MemberList").addClass("loading");
    $.ajax({
        type: "POST",
        url: "http://" + host + "/services/picklists.asmx/GetAllPicklists",
        data: "{'customer':'" + $('#select-customer').val() + "', 'route':'" + $('#select-route').val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnGetAllPicklistsSuccess,
        error: OnError
    });
}

我已经修改了 webservice 函数以提供 JSON,但正在进行中...... :)

一切都按预期工作,但我希望使GetData中 的连接字符串s动态。我应该如何设置一个(尚未定义的)连接对象,其值为Data Source (IP)、User IdPasswordDefault Collection。具体如何在 jquery POST数据参数中传递该连接对象和服务函数调用参数?以后登录时可以设置这个连接对象吗?

请随时提出问题以澄清您不清楚的事情。

提前致谢!

4

1 回答 1

0

通过服务调用传递数据不是一个好的选择。您的 sql 连接字符串很容易被黑客入侵。您可以使用 wcf 服务并使用消息契约来传递信息。

于 2013-03-27T11:33:34.163 回答