I would like to ask for help on creating web service.
I created a method that will insert into a sql database through Invoke. However, at consuming (after adding web reference), i have a form that has all the textbox and button. I invoke the method at the button, but all the details can save into the web service database. What must i do to make it save? Is it my method wrong?
<WebMethod()> _ Public Sub insertNewCustomer(ByVal cUserName As String, ByVal cFirstName As String, ByVal cLastName As String, ByVal cGender As String, ByVal cPassword As String, ByVal cPasswordQns As String, ByVal cPasswordAns As String, ByVal cCountry As String) conn = dbConnection.getfakeGoogleConnection() Try conn.Open() Dim strInsert As String strInsert = "INSERT INTO [Customer] ([UserName],[FirstName],[LastName],[Gender],[Password],[PasswordQns],[PasswordAns],[Country]) values (@UserName,@FirstName,@LastName,@Gender,@Password,@PasswordQns,@PasswordAns,@Country)" Dim cmd As New SqlCommand cmd.CommandText = strInsert cmd.CommandType = CommandType.Text cmd.Parameters.Add(New SqlParameter("@UserName", cUserName)) cmd.Parameters.Add(New SqlParameter("@FirstName", cFirstName)) cmd.Parameters.Add(New SqlParameter("@LastName", cLastName)) cmd.Parameters.Add(New SqlParameter("@Gender", cGender)) cmd.Parameters.Add(New SqlParameter("@Password", cPassword)) cmd.Parameters.Add(New SqlParameter("@PasswordQns", cPasswordQns)) cmd.Parameters.Add(New SqlParameter("@PasswordAns", cPasswordAns)) cmd.Parameters.Add(New SqlParameter("@Country", cCountry)) cmd.Connection = conn cmd.ExecuteNonQuery() conn.Close() Catch ex As Exception End Try End Sub
There might be an exception in your Try block and the command execution does not complete successfully.
Putting an empty Catch block is worse than not having implemented any exception handling.
At least you know when you hit an error when not using Try block. Having empty Catch block will only supressed errors and making your troubleshooting more complex.
Just put a break point to see where you hit an error.
If my guess is correct, you are having Security exception as the work process account (ASPNET - IIS 5, NETWORK SERVICE - IIS 6) may not have an appropriate permission to connect to your database or inserting records.