VB/JQuery webservice problem


I've hit a bit of a problem with a jQuery and a webservice. The webservice is in VB.NET and it's been quite a while since I last did anything in VB or a webservice.

Thing is, I'm not sure if the problem is in the query or in the code. All I get when I run is a button (which is correct) and after I click it, I get an error 500 - which doesn't really help.

The query (below) has security issues which I'm completely aware of - but as it's for my own use, that's ok - I can tidy that up at some point if I decide to use it.


A quick and dirty hack

$(document).ready(function() {
$("#btnMore").click(function() {
contentType: "application/json; charset=utf-8",
url: "WebService1.asmx/GetData",
data: "{'localhost', 'paul', '', 'Database1', {'SELECT','Name','where','age > 25','and','hometown == Liverpool'}, {'','','',''}",
success: onSuccess,
error: onError

function onSuccess(result)
var strings = result.d;
for (var i = 0; i < strings.length; ++i)
$("#datalist").append("" + strings[i] + "");

function onError(result)
alert(result.status + ": " + result.statusText);


I have a feeling that it's down to what I'm passing into the webservice rather than the webservice

Public Class WebService1
Inherits System.Web.Services.WebService

Public Function GetData(ByVal server As String, ByVal uid As String, ByVal pw As String, _
ByVal db As String, ByVal cmds As ArrayList, ByVal tbl As ArrayList) As DataSet
Dim connection As SqlConnection
Dim data As New DataSet("GetData")
Dim constr As String = "server=" + server + "; uid=" + uid + "; pwd=" + pw + "; database=" + db
connection = New SqlConnection(constr)
For i = 0 To cmds.Count
If (Not (cmds(i).ToString()).StartsWith(("SELECT" Or "Select"))) Then
Throw MySQLException("The SQL command must start with SELECT or Select")
End If
Dim command As New SqlCommand
command.Connection = connection
command.CommandText = cmds(i).ToString()
Dim dataadapter As New SqlDataAdapter
dataadapter.SelectCommand = command
dataadapter.TableMappings.Add("Table", tbl(i).ToString())
Return data

Catch ex As System.Data.SqlClient.SqlException
End Try
End Function

Private Function MySQLException(ByVal p1 As String) As Exception
Throw New NotImplementedException
End Function

End Class[/code]

I'm using VS2010 and if I set a debug point in the VB webservice, it comes up with a webpage which gives me the method but the error is odd - it's saying the parameters needed have to be primitives rather than generics. I know I can pass generics into a webservice in C#, so I'm wondering if this is a VB problem more than anything.

The database has been set up in VS2010, so I'm assuming it's an mssql one so the connection code should be right (though the connection string may not be - the database is called Database1 and I'm using Table1 - do I pass Database1 or Table1 in via the jQuery?)

Any help, advice or pointers in the right direction on this would be appreciated. It's been ages since I've done any webservices and possibly longer since doing anything in anger with VB.NET!


P.S. I originally posted this on the webserver forum... sorry...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!