Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Web service in asp.net using c#

Web service in asp.net using c#

Scheduled Pinned Locked Moved C#
csharpdatabasehelpasp-netsql-server
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akosidandan
    wrote on last edited by
    #1

    Hello experts, I would like to ask again if how will I'm going to edit my web services because it seems that it's only working on my local machine. I tried to upload my web service and the 2 database(ms access 2003 and sql server 2005 express) to a free asp.net hosting site but I got and error that I cant access the database. I detach my sql server 2005 express to my sqlSERVER Management studio before I upload it. Below is my sample code to my asmx file.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;

    //sql client import

    using System.Data.SqlClient;
    using System.Data;

    using System.Data.OleDb;

    namespace WebService1
    {
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    //[WebService(Namespace = "http://tempuri.org/")]
    //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        \[WebMethod\]
        public DataTable getData()
        {
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\\\MemberSites\\\\MemberSites\_AspSpider\_Info\\\\akosiDAN\\\\database\\\\Database1.mdb");
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            ds.Tables.Add(dt);
    
            OleDbDataAdapter da = new OleDbDataAdapter ("Select \* from phonebooktable",con);
            da.Fill (dt);
    
            return dt;
        }
    
        \[WebMethod\]
        public DataTable getData()
        {
            SqlConnection con = new SqlConnection("server= DANDAN-PC\\\\SQLEXPRESS;uid=MYID;pwd=MYPASSWORD;database=phonebookdatabase");
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            ds.Tables.Add(dt);
    
            SqlDataAdapter da = new SqlDataAdapter("Select \* from phonebooktable", con);
    
            da.Fill(dt);
    
            return dt;
        }
    }
    

    }

    Any help are kindly appreciated. Thanks, DAN

    L D P 3 Replies Last reply
    0
    • A akosidandan

      Hello experts, I would like to ask again if how will I'm going to edit my web services because it seems that it's only working on my local machine. I tried to upload my web service and the 2 database(ms access 2003 and sql server 2005 express) to a free asp.net hosting site but I got and error that I cant access the database. I detach my sql server 2005 express to my sqlSERVER Management studio before I upload it. Below is my sample code to my asmx file.

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Services;

      //sql client import

      using System.Data.SqlClient;
      using System.Data;

      using System.Data.OleDb;

      namespace WebService1
      {
      /// <summary>
      /// Summary description for Service1
      /// </summary>
      //[WebService(Namespace = "http://tempuri.org/")]
      //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      //[System.ComponentModel.ToolboxItem(false)]
      // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
      // [System.Web.Script.Services.ScriptService]
      public class Service1 : System.Web.Services.WebService
      {

          \[WebMethod\]
          public DataTable getData()
          {
              OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\\\MemberSites\\\\MemberSites\_AspSpider\_Info\\\\akosiDAN\\\\database\\\\Database1.mdb");
              DataSet ds = new DataSet();
              DataTable dt = new DataTable();
              ds.Tables.Add(dt);
      
              OleDbDataAdapter da = new OleDbDataAdapter ("Select \* from phonebooktable",con);
              da.Fill (dt);
      
              return dt;
          }
      
          \[WebMethod\]
          public DataTable getData()
          {
              SqlConnection con = new SqlConnection("server= DANDAN-PC\\\\SQLEXPRESS;uid=MYID;pwd=MYPASSWORD;database=phonebookdatabase");
              DataSet ds = new DataSet();
              DataTable dt = new DataTable();
              ds.Tables.Add(dt);
      
              SqlDataAdapter da = new SqlDataAdapter("Select \* from phonebooktable", con);
      
              da.Fill(dt);
      
              return dt;
          }
      }
      

      }

      Any help are kindly appreciated. Thanks, DAN

      L Offline
      L Offline
      Lukasz Nowakowski
      wrote on last edited by
      #2

      My first idea: I see you have connection strings hardcoded into your source code. Are you changing them before uploading to match configuration from the hosting server? If not, it can't work, because (most likely) your service cannot find server DANDAN-PC, nor file "C:\\MemberSites\\MemberSites_AspSpider_Info\\akosiDAN\\database\\Database1.mdb". You should move both those connection strings to the web.config file.

      Don't forget to rate answer, that helped you. It will allow other people find their answers faster.

      A B 2 Replies Last reply
      0
      • L Lukasz Nowakowski

        My first idea: I see you have connection strings hardcoded into your source code. Are you changing them before uploading to match configuration from the hosting server? If not, it can't work, because (most likely) your service cannot find server DANDAN-PC, nor file "C:\\MemberSites\\MemberSites_AspSpider_Info\\akosiDAN\\database\\Database1.mdb". You should move both those connection strings to the web.config file.

        Don't forget to rate answer, that helped you. It will allow other people find their answers faster.

        A Offline
        A Offline
        akosidandan
        wrote on last edited by
        #3

        Hello, Thanks for the reply,I tried changing my connection strings now provided in my web hosting site. The connection strings given by my host is in this link http://www.aspspider.com/tips/Tip18.aspx[^] I'm not that so much sure but doesn't the ms access database supposed to work since I followed it. I tried commenting the one using sql server connection string just to test the ms access 2003 and I even tried to re add my web reference to be sure but still I got an error. To give clarification my error is in below

        System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

        I'm also confuse since why does my error state that I have error in sql but I'm using oledb since my database is ms access 2003 and I already comment the block of code using sql. Any help are kindly appreciated. Thanks, DAN

        1 Reply Last reply
        0
        • A akosidandan

          Hello experts, I would like to ask again if how will I'm going to edit my web services because it seems that it's only working on my local machine. I tried to upload my web service and the 2 database(ms access 2003 and sql server 2005 express) to a free asp.net hosting site but I got and error that I cant access the database. I detach my sql server 2005 express to my sqlSERVER Management studio before I upload it. Below is my sample code to my asmx file.

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Web;
          using System.Web.Services;

          //sql client import

          using System.Data.SqlClient;
          using System.Data;

          using System.Data.OleDb;

          namespace WebService1
          {
          /// <summary>
          /// Summary description for Service1
          /// </summary>
          //[WebService(Namespace = "http://tempuri.org/")]
          //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
          //[System.ComponentModel.ToolboxItem(false)]
          // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
          // [System.Web.Script.Services.ScriptService]
          public class Service1 : System.Web.Services.WebService
          {

              \[WebMethod\]
              public DataTable getData()
              {
                  OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\\\MemberSites\\\\MemberSites\_AspSpider\_Info\\\\akosiDAN\\\\database\\\\Database1.mdb");
                  DataSet ds = new DataSet();
                  DataTable dt = new DataTable();
                  ds.Tables.Add(dt);
          
                  OleDbDataAdapter da = new OleDbDataAdapter ("Select \* from phonebooktable",con);
                  da.Fill (dt);
          
                  return dt;
              }
          
              \[WebMethod\]
              public DataTable getData()
              {
                  SqlConnection con = new SqlConnection("server= DANDAN-PC\\\\SQLEXPRESS;uid=MYID;pwd=MYPASSWORD;database=phonebookdatabase");
                  DataSet ds = new DataSet();
                  DataTable dt = new DataTable();
                  ds.Tables.Add(dt);
          
                  SqlDataAdapter da = new SqlDataAdapter("Select \* from phonebooktable", con);
          
                  da.Fill(dt);
          
                  return dt;
              }
          }
          

          }

          Any help are kindly appreciated. Thanks, DAN

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          This code shouldn't even compile. You've got the exact same method (getData) defined twice, with no difference between the two method headers. There has to be some way to deifferentiate the two either by name or by the parameter list.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          A 2 Replies Last reply
          0
          • D Dave Kreskowiak

            This code shouldn't even compile. You've got the exact same method (getData) defined twice, with no difference between the two method headers. There has to be some way to deifferentiate the two either by name or by the parameter list.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            A Offline
            A Offline
            akosidandan
            wrote on last edited by
            #5

            Hello, Sorry for the confusing part. I was trying to test only if how it work by commenting other or vice versa in that time thats why I have the two methods. Thanks for the reply. Any help are kindly appreciated. Thanks, DAN

            1 Reply Last reply
            0
            • L Lukasz Nowakowski

              My first idea: I see you have connection strings hardcoded into your source code. Are you changing them before uploading to match configuration from the hosting server? If not, it can't work, because (most likely) your service cannot find server DANDAN-PC, nor file "C:\\MemberSites\\MemberSites_AspSpider_Info\\akosiDAN\\database\\Database1.mdb". You should move both those connection strings to the web.config file.

              Don't forget to rate answer, that helped you. It will allow other people find their answers faster.

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              Indeed. Both connection strings are absolute paths to things that are on the local machine, and almost certainly won't be in the same place when hosted. Make sure the connection strings in the uploaded version point to where the database actually is (your host should be able to tell you this). And indeed, connection strings should be in a configuration file, so your code base can be the same for testing and deployment.

              A 1 Reply Last reply
              0
              • A akosidandan

                Hello experts, I would like to ask again if how will I'm going to edit my web services because it seems that it's only working on my local machine. I tried to upload my web service and the 2 database(ms access 2003 and sql server 2005 express) to a free asp.net hosting site but I got and error that I cant access the database. I detach my sql server 2005 express to my sqlSERVER Management studio before I upload it. Below is my sample code to my asmx file.

                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Web;
                using System.Web.Services;

                //sql client import

                using System.Data.SqlClient;
                using System.Data;

                using System.Data.OleDb;

                namespace WebService1
                {
                /// <summary>
                /// Summary description for Service1
                /// </summary>
                //[WebService(Namespace = "http://tempuri.org/")]
                //[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
                //[System.ComponentModel.ToolboxItem(false)]
                // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
                // [System.Web.Script.Services.ScriptService]
                public class Service1 : System.Web.Services.WebService
                {

                    \[WebMethod\]
                    public DataTable getData()
                    {
                        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\\\MemberSites\\\\MemberSites\_AspSpider\_Info\\\\akosiDAN\\\\database\\\\Database1.mdb");
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable();
                        ds.Tables.Add(dt);
                
                        OleDbDataAdapter da = new OleDbDataAdapter ("Select \* from phonebooktable",con);
                        da.Fill (dt);
                
                        return dt;
                    }
                
                    \[WebMethod\]
                    public DataTable getData()
                    {
                        SqlConnection con = new SqlConnection("server= DANDAN-PC\\\\SQLEXPRESS;uid=MYID;pwd=MYPASSWORD;database=phonebookdatabase");
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable();
                        ds.Tables.Add(dt);
                
                        SqlDataAdapter da = new SqlDataAdapter("Select \* from phonebooktable", con);
                
                        da.Fill(dt);
                
                        return dt;
                    }
                }
                

                }

                Any help are kindly appreciated. Thanks, DAN

                P Offline
                P Offline
                Prasanta_Prince
                wrote on last edited by
                #7

                Have a look on the connection string of the MDB file. or use Server.Mappath to get actual path of the mdb file.

                A 1 Reply Last reply
                0
                • P Prasanta_Prince

                  Have a look on the connection string of the MDB file. or use Server.Mappath to get actual path of the mdb file.

                  A Offline
                  A Offline
                  akosidandan
                  wrote on last edited by
                  #8

                  Hello, I fix now the problem it seems that one causing the error is the bin file of my webservice. I notice that although I edit the code of my asmx file and even if its a working but if I did not re upload the the bin file of my webservice.The website still load the past code of my asmx rather than the new one. Thanks also for the server.mappath if was a great help to map the path of my files. Thanks everyone, DAN

                  1 Reply Last reply
                  0
                  • B BobJanova

                    Indeed. Both connection strings are absolute paths to things that are on the local machine, and almost certainly won't be in the same place when hosted. Make sure the connection strings in the uploaded version point to where the database actually is (your host should be able to tell you this). And indeed, connection strings should be in a configuration file, so your code base can be the same for testing and deployment.

                    A Offline
                    A Offline
                    akosidandan
                    wrote on last edited by
                    #9

                    Hello, I fix now the problem it seems that one causing the error is the bin file of my webservice. I notice that although I edit the code of my asmx file and even if its a working code but if I did not re upload the the bin file of my webservice.The website still load the past code of my asmx rather than the new one. Thanks everyone, DAN

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      This code shouldn't even compile. You've got the exact same method (getData) defined twice, with no difference between the two method headers. There has to be some way to deifferentiate the two either by name or by the parameter list.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak

                      A Offline
                      A Offline
                      akosidandan
                      wrote on last edited by
                      #10

                      Hello, I fix now the problem it seems that one causing the error is the bin file of my webservice. I notice that although I edit the code of my asmx file and even if its a working but if I did not re upload the the bin file of my webservice.The website still load the past code of my asmx rather than the new one. Thanks everyone, DAN

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups