ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wendi Turner

    ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005

    ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005
    ---------------------------------------------------------------------------------------------------

    I have successfully created a webservice in ASP.NET 2.0 C# with VS
    2005 & VS 2008, however, i can find nothing - books or otherwise to
    help with the webservice connection to the database.

    Can anyone please offer help on what to return in the method that
    makes a select statement to the database and HOW to connect to the
    database?? Do i use DataSets, TableAdapters, drivers???

    How??
  • mr t

    #2
    Re: ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005

    On May 5, 2:56 pm, Wendi Turner <wenditur...@gm ail.comwrote:
    ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005
    ---------------------------------------------------------------------------­------------------------
    >
    I have successfully created a webservice in ASP.NET 2.0 C# with VS
    2005 & VS 2008, however, i can find nothing - books or otherwise to
    help with the webservice connection to the database.
    >
    Can anyone please offer help on what to return in the method that
    makes a select statement to the database and HOW to connect to the
    database??   Do i use DataSets, TableAdapters, drivers???
    >
    How??
    What do you mean connect to database?

    Your DB -Your webservice -The Client

    Make select statements in your web service the return the result to
    the client. DO NOT process any SQL statements from the client.

    Comment

    • =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?=

      #3
      Re: ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005

      Here is an example of one way in which to connect to an Oracle database. For
      Sql server you would use the relevant SqlServer database connection classes.

      [WebMethod]
      public Int32 GetCountJobs()
      {
      OracleConnectio n connection = new OracleConnectio n();

      connection.Conn ectionString = "my_connection_ string";

      OracleCommand command = connection.Crea teCommand();

      try
      {
      connection.Open ();

      command.Command Text = "SELECT COUNT (*) FROM JOB";

      return Convert.ToInt32 (command.Execut eScalar());
      }
      catch
      {
      return 0;
      }
      finally
      {
      command.Dispose ();
      connection.Clos e();
      connection.Disp ose();
      }
      }

      David
      On May 5, 2:56 pm, Wendi Turner <wenditur...@gm ail.comwrote:
      ASP.NET 2.0 C# WebService Connect to Database: Sql Server 2005
      ---------------------------------------------------------------------------­------------------------

      I have successfully created a webservice in ASP.NET 2.0 C# with VS
      2005 & VS 2008, however, i can find nothing - books or otherwise to
      help with the webservice connection to the database.

      Can anyone please offer help on what to return in the method that
      makes a select statement to the database and HOW to connect to the
      database?? Do i use DataSets, TableAdapters, drivers???

      How??

      Comment

      Working...