Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 901387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:32:51+00:00 2026-05-15T15:32:51+00:00

I’m a fairly new programmer and very new to web programming and I need

  • 0

I’m a fairly new programmer and very new to web programming and I need some ASP.NET remediation. I’m trying to implement an autocomplete control in a form. When I put the search logic in the form codebehind, everything works. However, once I move the search logic to a web service (the autocomplete is still calling the same method in the form code), everything goes screwy. I’m using an OleDb connection and trying to access a test db on my workstation, but I get an error saying that the server is inaccessible.

Obviously, I could stick with the aspx codebehind, but regardless I need to understand the basic workings of a web service. Can someone help me understand where I’m making the error?

What I have looks like this:

Form.aspx.cs

 ...
 [System.Web.Services.WebMethod]
 [System.Web.Script.Services.ScriptMethod]
 public static string[] GetContacts(string prefixText, int count)
 {
     AutoCompleteService autoCompleteService = new AutoCompleteService();
     autoCompleteService.QueryString = "SELECT ...";
     autoCompleteService.ConnectionString = UserContext.ConnectionString;
     return autoCompleteService.GetResults(prefixText, count);
 }
 ...

AutoComplete.Service.asmx

<%@ WebService Language="C#" CodeBehind="AutoComplete.Service.cs" Class="AutoCompleteService" %>

AutoComplete.Service.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Data;

[WebService(Namespace = "http://tempuri.org/")]
[System.Web.Script.Services.ScriptService]
public class AutoCompleteService : System.Web.Services.WebService {

    public string QueryString;
    public string ConnectionString;

    public AutoCompleteService()
    {
        QueryString = "";
        ConnectionString = "";
    }

    [WebMethod]
    public String[] GetResults(string prefixText, int count)
    {
        ...
    }

    private String[] GetNameListFromDB()
    {
       List<string> resultList = new List<string>();
       OleDbConnection connection = new OleDbConnection(ConnectionString);
       connection.Open();  //Exception thrown here.
       ...
    }

Exception

ServerVersion = 'connection.ServerVersion' threw an exception of type 'System.InvalidOperationException'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:32:52+00:00Added an answer on May 15, 2026 at 3:32 pm

    You call the CodeBehind, and that just instantiates the class. it does not use the service.

    with your client javascript library, you can call the service directly.
    without the code in codeBehind. but that depends on your clientside js library.

    what i would recommend you is, get to lern MVC, or asp.net MVC, as they have such things much simpler, and with easier implemention in the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.