Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web Services: C#

Status
Not open for further replies.

suhash

Programmer
Joined
Aug 15, 2005
Messages
10
Location
GB
Hi There,

I have a web service (its very simple). In the same solution I have a C# (class) and VB (form). I am using the VB form to check the c# class.

Now. I have a web service that expose a c# method. following is the web service code.
DBHandle.HandleDB PeerInfo;
private int IsPeerValid = 0;
[WebMethod]
public int IsAValidPeer(int intPeerID)
{
PeerInfo = new DBHandle.HandleDB();
int intLocalPeerID = intPeerID;
bool boolPeerStatus= false;
boolPeerStatus = PeerInfo.IsValidPeer(intLocalPeerID);
if (boolPeerStatus)
{
IsPeerValid = 1;
}
return IsPeerValid;
}

the code for IsValidPeer method is:

public bool IsValidPeer(int intPeerID)
{
String dbPeerValidProcedure;
int intProcedureReturn;
bool isValid = false;
bool openDB;
openDB = OpenDatabase();
//Database should now be opended
if (openDB == false)
{
Console.WriteLine("Can not open Database");

}
else
{
dbPeerValidProcedure = "CheckPeerID"; //Name of the stored procedure
dbCommand = new System.Data.SqlClient.SqlCommand(dbPeerValidProcedure, dbConnection);
dbCommand.CommandType = System.Data.CommandType.StoredProcedure;
dbParameter = dbCommand.Parameters.Add("@P_ID", System.Data.DbType.Int32);
dbParameter.Direction = System.Data.ParameterDirection.Input;
dbCommand.Parameters["@P_ID"].Value = intPeerID;
try
{
intProcedureReturn = (int) dbCommand.ExecuteScalar();
isValid = true;
Console.WriteLine(intProcedureReturn);
}
catch(System.Exception StoredProcedureException)
{
Console.WriteLine("Stored procedure exception" + StoredProcedureException.ToString());
}
}
if (!CloseDatabase())
{
Console.WriteLine("could not close Database");
}
return isValid;
}

My question is:

(1) When I tested the method from VB form the correct int value is returned (1), but when I share the method over the Web Service I dont get the correct value. I get 0. I can not see why this happens..Any ideas?

Thanks in advance.

Mal.
 
Guys,

Problem solved..

It was my mistake. I hadn't add ASPNET as a user for the database....Sorry

Thanks,,,,

Mal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top