views:

225

answers:

4

Okay this question could either be very broad or very specific because I am not sure if I am going about this in a fundamentally wrong way or if I am close to correct.

First an overview: What I am trying to do it create a server application for all of the clients in my organization to connect to. I think the best way to do this is to use a web service. Please correct me if I am wrong!

Anyway, if I use a web service I need the web service(server) to connect to the database. In MS Visual studio when you add a web service project the data menu disappears and you can't add a data source to the project. There may be a workaround for this by hand coding this, but I am not sure how to do it. This is my first time working with a web service and ASP.NET so I am a real noob in this area.

Any help would be greatly appreciated!!!

+1  A: 

Add your database connection string to the <connectionStrings/> section of the web service web.config file. Check this web site for a list of the most common database connection strings: Connectionstrings.com

alexs
A: 

You would use standard ADO.Net commands and SQL statements, rather than using the dataset designer. Example (IN VB)

    <WebMethod()> _
    Public Function DoesOpenCallExist(ByVal CustID As String, ByVal CallType As String, ByVal SubCallType As String) As Boolean
     Dim returnvalue As Boolean = False
     ' first, entry validation
        ' snip - code deleted


      Dim conn As New System.Data.SqlClient.SqlConnection
      conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("HEATConnectionString").ConnectionString
      Dim cmd As New SqlClient.SqlCommand
      cmd.Connection = conn
         cmd.CommandType = CommandType.StoredProcedure  
      cmd.CommandText = "sp_GetCallCount"
         cmd.Parameters.AddWithValue("@CustID", CustID)
         ' Etc...
      Try
          conn.Open()
          returnvalue = cmd.ExecuteScalar() > 0
      Catch ex As Exception
          Throw New Exception(ex.ToString())
         Finally
          conn.Close()
      End Try
      Return returnvalue
End Function
David Stratton
A: 

*This should be done

  • web.config file*

here the datsource is the servername,initial catlog is the databasename and the userid ur sql userid and the password is as same.

And then in the class we want to get connect with the database......

  • **class.cs**

public class connect { public static SqlConnection con() { String con= ConfigurationManager.AppSettings["connections"].ToString(); SqlConnection cn = new SqlConnection(con); cn.Open(); return cn; } }

here the connection is the keyname...... ok i think its sufficient............

Sudhakar K
A: 

This is too broad-based and fundamental question to try to answer here. Read some tutorials. Here's a link for you http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx

Cyril Gupta