Client/Server application with SQL Database on Server side? C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • berilker
    New Member
    • Jan 2010
    • 3

    Client/Server application with SQL Database on Server side? C#

    I have a project. I have to build a client server application and i have to access(and run some queries) to ms sql database which is at server side, from client application. How can i build this structure? Client should use tcp to connect server and access to database at server's side.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    So your question really is
    "How do I build an entire client/server database-enabled application?" ?

    I am reminded of the the old story:
    Q: How do I eat an elephant, its so big?
    A: One little bite at a time.

    So in your case the answer would be: One little byte at a time.
    1. Get a set of whiteboards
    2. Get a discount card for your best bookstore
    3. Identify all the major components and needs. This is everything from defining all the datastructures you need to pass around to the various screens and levels of permissions your users will need. Who can edit data and who can only see it?
    4. Identify all the technologies that you think you need.
    5. Identify all the technologies that you don't understand.
    6. Make a project just for learning that one technology: Database; TCP/IP communication, XML serialization, whatever
    7. Learn each small part on it's own. (This is where the bookstore loyalty program card comes in)
    8. Then start version 1 of the big project where you start integrating all your new knowledge.
    9. After making version 1 and learning and realizing all the places where you could have done something better, start completely fresh with a new project to be version 2.

    Comment

    • One1
      New Member
      • Sep 2010
      • 1

      #3
      How to connect to SQL Server from C#

      To connect to SQL Server from C#.NET, you need to create a connection string such as below:

      private SqlConnection connection;
      private string connectionStrin g =
      @"Server=(local );Database=Embe dding_SQL_Test; User ID=sa;Password= 123";
      connection = new SqlConnection( connectionStrin g );

      Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:
      SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);

      The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.

      Next to execute the SQL queries in the database, you use the following methods:
      ExecuteReader - to execute SELECT queries
      ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.

      This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database.
      For details about the connection string, the methods and their parameters check the following link: ( http://www.shahriarnk.com/Shahriar-N...harp-Java.html )
      Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.

      Comment

      Working...