Pass connection object to ASP.Net webservice from jQuery

kathrynkomodo

New Member
I have a webservice providing AS400 data.This webservice has a fixed connection string that I wish to make dynamic.See code below:\[code\] 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 = http://stackoverflow.com/questions/15654728/dat.Tables(0) Catch ex As Exception _data = New DataTable End Try Return _data End Function\[/code\]A sample webservice function that uses the above:\[code\]<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 = http://stackoverflow.com/questions/15654728/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\[/code\]The above function gets called by jquery:\[code\]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 });}\[/code\]I have modified the webservice function to provide JSON but that's work in progress... :)Everything is working as expected, but I wish to make the connection string sfrom GetData dynamic. How should I go about setting a (not yet defined) connection object with values for Data Source (IP), User Id, Password and Default Collection.Specifically how to pass that connection object and the service function call parameters in the jquery POST data parameter? Is it possible to set this connection object at login in the future?Please feel free to ask questions to clarify things that are unclear to you.Thanks in advance!
 
Back
Top