المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : No connection could be made because the target machine actively refused it



C# Programming
09-19-2009, 06:00 AM
Dear Sir,
I know its very common problem which has been asked by many people but i did not get any of the persons way of immplementing Remoting as i did so please go through with my steps of my project and provide me solution...
The steps which i used in my program ....
Server Side Code...
my app.config code









</br /br / br /br /br /connectionStrings>










</br /br / br /br /br /appSettings>
















</br /br / br /br /br /service>









</br /br / br /br /br /channels>

</br /br / br /br /br /application>



</br /br / br /br /br /system.runtime.remoting>

</br /br / br /br /br /configuration>

Server.cs


using



System;

using



System.Collections.Generic;

using



System.Text;

using



System.Data;

using



System.Data.SqlClient;

using



System.Configuration;

using



System.Runtime.Remoting.Lifetime;

using



System.Runtime.Remoting.Channels;

using



System.Runtime.Remoting.Channels.Tcp;

namespace



Vital.DotNet.Server

{




class LogIn:MarshalByRefObject,Vital.DotNet.Server.IvitalServerInterfaces

{




SqlDataAdapter adap;




SqlCommand cmd;




SqlConnection con;




public DataSet retriveData(string authorFirstName,string authorLastName,out bool isSuccess)

{





con =

new SqlConnection("initial Catalog=pubs ;uid=sa;pwd=success; server=VITAL-17\\VITAL17;integrated security=true");

con.Open();




SqlCommand cmd = new SqlCommand("Demoinput", con);

cmd.CommandType=


CommandType.StoredProcedure;

cmd.Parameters.Add(


new SqlParameter("@au_fname",authorFirstName));

cmd.Parameters.Add(


new SqlParameter("@au_lname",authorLastName));




DataSet ds = new DataSet();




SqlDataAdapter adap = new SqlDataAdapter(cmd);

adap.Fill(ds);




if (ds.Tables[0].Rows.Count == 0)

{

isSuccess =


false;

}




else

{

isSuccess =

true;

}




return ds;

}




static void Main(string[] args)

{




Console.ReadLine();



}

}

}

My procedure in pubs data base

create procedure [dbo].[Demoinput]( @au_lname varchar(50),@au_fname varchar(50))
as
begin
select * from authors
where au_lname=@au_lname
end

Interface on server side which has been added on client side as a DLL.


namespace




Vital.DotNet.Server

{




public interface IvitalServerInterfaces

{



DataSet retriveData(string authorFirstName, string authorLastName, out bool isSuccess);

}

}






CLIENT Side Code

client side app.config file


















</br /br / br /br /br /appSettings>













</br /br / br /br /br /channels>

</br /br / br /br /br /application>

</br /br / br /br /br /system.runtime.remoting>

</br /br / br /br /br /configuration>






client.cs



using




System;

using



System.Collections.Generic;

using



System.ComponentModel;

using



System.Data;

using



System.Drawing;

using



System.Text;

using



System.Windows.Forms;

using



Vital.DotNet.Server;

using



System.Configuration;

using



System.Runtime.Remoting.Lifetime;

using



System.Runtime.Remoting.Channels;

using



System.Runtime.Remoting.Channels.Tcp;

namespace



Vital.DotNet.client

{




public partial class Form1 : Form

{

Vital.DotNet.Server.

IvitalServerInterfaces ObjServerSide = null;




bool isSuccess = false;




public Form1()

{

InitializeComponent();

}




private void btnShow_Click(object sender, EventArgs e)

{




try

{

ObjServerSide = (

IvitalServerInterfaces)Activator.GetObject(typeof(IvitalServerInterfaces), @"tcp://192.168.1.17" + ":8080" + "/pop");

ObjServerSide.retriveData(txtAuthorFirstName.Text, txtAuthorLastName.Text,


out isSuccess);

}




catch (System.Runtime.Remoting.RemotingException ex)

{




MessageBox.Show(ex.Message);

}

}

}

}

please help me out from this problem ,i checked this code on remote computer(On LAN) as well as same computer but it doesnot work....

Thanks and regards
AMRITA VISHNOI

hi this is amrita.
Amrita