dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Accessing remote SQL server by remoting (TCP)

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    7

    Accessing remote SQL server by remoting (TCP)

    Introduction:

    In this sample describes how to build a distribution application which accesses MS SqlServer2000 on remoting service.

    Using the code

    Server

    using System;

    using System.Data;

    using System.Data.SqlClient;



    namespace www.treaple.com

    {

    public class Hello : System.MarshalByRefObject

    {

    public Hello()

    {

    Console.WriteLine("Hello actived");

    }



    ~Hello()

    {

    Console.WriteLine("Hello destroyed");

    }



    public DataSet GetData()

    {

    string conn = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI";//newSqlConnectionSystem.Configuration.ConfigurationSettings.AppSettings["strconn"]);
    SqlDataAdapter da = new SqlDataAdapter("select * from Products", conn);

    DataSet ds = new DataSet();

    da.Fill(ds);

    return ds;

    }

    }
    }

    Client



    using System;

    using System.Runtime.Remoting;

    using System.Runtime.Remoting.Channels;

    using System.Runtime.Remoting.Channels.Tcp;

    using System.Data;



    namespace www.treaple.com

    {

    public class Client

    {

    [STAThread]

    public static void Main(string[] args)

    {

    //TcpChannel chan = new TcpChannel();

    ChannelServices.RegisterChannel(new TcpClientChannel());

    Hello obj = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8085/Hi");

    DataTable dt = obj.GetData().Tables[0];

    foreach (DataRow dr in dt.Rows)

    {

    Console.WriteLine(dr["ProductID"] + " " + dr["ProductName"]);

    }

    //if (obj == null) System.Console.WriteLine("Could not find server");

    //else Console.WriteLine(obj.Greeting("kk"));

    //else Console.WriteLine(obj.HelloMethod("John"));



    }

    }

    }

    Interface:


    using System;



    namespace www.treaple.com

    {

    public interface IHello

    {

    String HelloMethod(String name);

    }



    public class HelloServer : MarshalByRefObject, IHello

    {

    public HelloServer()

    {

    Console.WriteLine("HelloServer actived");

    }



    public String HelloMethod(String name)

    {

    Console.WriteLine("Hello.HelloMethod : {0}", name);

    return "hello" + name;

    }

    }
    }
    Treaple offshore outsourcing software solutions providing mobile(Pocket pc,smartphone and wince.net) software,mobile GIS(Mobile map),Desktop GIS(Desktop map), GPS,GSM Locating Services,Voip,Multimedia(Audio,Video) and web design offshore outsourcing software development services.We have developed lots of projects on Microsoft Poccket pc 5.0/6.0,smartphone 5.0/6.0 and Microsoft windows and got strong background in Microsoft MapPoint, ESRI ArcGIS, Map info,Google map etc
    Our website below: http://www.treaple.com

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Accessing remote SQL server by remoting (TCP)

    Is there a question or it is just a tip. It is better if you write the detail and please use CODE tags when you post code.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,248

    Re: Accessing remote SQL server by remoting (TCP)

    If there isn't a question, you may want to post this in the Announcements forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)