PDA

View Full Version : Web services randomly working


bruce
04-02-2004, 04:54 AM
Can't really tell what's happening until we see the error. Try block out your error trapping and see what error did you get.

[b]quote:Originally posted by sleonard

I have created two web services on DASP, and neither one of them are working correctly. They are randomly going up and down. I am using C#, ADODB and MySQL. The web service simply executes a select statement on a value passed into the function and returns an array of resultant strings. No one else is hitting these, the databases currently have less than 10 records, and the resultant string arrays are 2 to 5 in length. I am setting the recordset to null and closing the connection after every call. If I run the service locally on my IIS box hitting the same DASP MySQL db, it works all the time, even when the DASP deployed service doesn't. Yesterday, when one of my services was down, it would return an array of two null strings on a hit record, which tells me it was executing the query and finding a record. A no hit query would return an zero length array. The only possible point of failure is here:

[quote]
sData=newstring;
rs.MoveFirst();
sData[0]=HttpUtility.UrlEncode((string)rs.Fields[0].Value);
sData=HttpUtility.UrlEncode((string)rs.Fields.Valu e);
</CODE>

This is in a try catch block and I am not seeing anything from my exception logger.

Any help would be appreciated,
sbl

P.S. As I was typing this, the one that was working for the last 12 hours went down and came back up...
</blockquote id="quote"></font id="quote">

sleonard
04-02-2004, 06:52 AM
Very lengthy update...
I had a bug in my exception handling/logging code... so I didn't see them.
Now I get this:

Source : mscorlib
Method : get_Keys
Date : 6:09:12 PM
Time : 4/2/2004
Computer : web999
Error : Object reference not set to an instance of an object.
Stack Trace : at System.Runtime.Remoting.Messaging.MessageDictionar y.get_Keys()
at TestVersionService.mxVersion.sArGetVersion(String sAppName) in Z:\YYY\testversionservice.root\testversionservice\ mxversion.asmx.cs:line 100
^^-------------------------------------------------------------------^^

Here is line 100:
[quote]
stringsTemp1=Convert.ToString(rs.Fields[0].Value);
</CODE>

Here is the entire web service:
[quote]
[WebMethod]
publicstring[]sArGetVersion(stringsAppName)
{
//declareavariableoftypeobjecttostorethereturnvaluef romthesqlstatementexecuted.
objectobj=null;

//avariableoftypestringtoreturntheversionassociatedw iththeapplication
string[]sData=newstring[0];
longlRecResult=0;
intiOpt=0;
try
{
iOpt=Convert.ToInt32(CommandTypeEnum.adCmdText);

sAppName=HttpUtility.UrlDecode(sAppName);
//CalliMakeDbConnectiontomakeconnectiontothedatabase
//ifreturnis0,databaseconnectionfailed.
//ifreturnis1,databaseconnectionsucceeded
if(this.iMakeDbConnection()!=0)
{
if(cn!=null)
{
//executeasqlstatementtogetthelatestversionforthisap pName.
rs=cn.Execute("selectVersion,URLfromappverurlwhereApplication='"+sAppName+"'",outobj,iOpt);
lRecResult=Convert.ToInt64(obj);
//Checktheresultoftheabovesqlstatement,return0,ifthe resultiszero,elsecontinue
if(lRecResult>0)
{
if(rs!=null)
{
rs.MoveFirst();
stringsTemp1=Convert.ToString(rs.Fields[0].Value);
stringsTemp2=Convert.ToString(rs.Fields.Value);
if((sTemp1!=null)&&(sTemp2!=null))
{
sData=newstring;
sData[0]=HttpUtility.UrlEncode(sTemp1);
sData=HttpUtility.UrlEncode(sTemp2);
if((sData[0]==null)||(sData==null))
{
if(sData[0]==null)
{
sData[0]="";
}
if(sData==null)
{
sData="";
}
thrownewException("Encodefieldvalueerror.lRecResultwas["+lRecResult.ToString()+"],Recordsetstatewas["+Convert.ToInt64(rs.State).ToString()+"],Recordsetstatuswas["+Convert.ToInt64(rs.Status).ToString()+"],Field0was["+sTemp1+"],Field1was["+sTemp2+"],Encode0was["+sData[0]+"],Encode1was["+sData+"].");
}
}
else
{
if(sTemp1==null)
{
sTemp1="";
}
if(sTemp2==null)
{
sTemp2="";
}
thrownewException("Fieldvalueerror.lRecResultwas["+lRecResult.ToString()+"],Recordsetstatewas["+Convert.ToInt64(rs.State).ToString()+"],Recordsetstatuswas["+Convert.ToInt64(rs.Status).ToString()+"],Field0was["+sTemp1+"],Field1was["+sTemp2+"].");
}
}
else
{
thrownewException("RecordsetwasnullandlRecResultwas["+lRecResult.ToString()+"].");
}
}
else
{
thrownewException("lRecResultwaszero.Couldeasilybe'notfound'onbadinpu t["+sAppName+"].");
}
}
else
{
thrownewException("Connectionwasnull.");
}
}
else
{
thrownewException("Unabletomakedbconnection.");
}
}
catch(Exceptionex)
{
//falseforwritinglogentrytocustomizedtextfile
boolbLogRet=ErrorLog.ErrorRoutine(false,ex);
}
finally
{
rs=null;
if((cn!=null)&&(cn.State!=Convert.ToInt32(ObjectStateEnum.adState Closed)))
{
cn.Close();
}
cn=null;
}
returnsData;
}

//Thisisaprivatefunctiontomakeconnectiontodatabase
//takesnoarguments
//returnvalueisaninteger.0todenoteunsuccessfulconnec tionanda1todenoteasuccessfulconnection
privateintiMakeDbConnection()
{
stringstrConnection="";
intiOpt=0;
intiRet=0;//return0todenoteaunsuccessfulconnection.

try
{
iOpt=Convert.ToInt32(ConnectOptionEnum.adConnectUn specified);
cn=newADODB.Connection();

//createaconnectionstring
strConnection="uid=nunya;pwd=bidness;server=mysql01.discountasp.n et;driver={MySqlODBC3.51Driver};database=MYSQLDB_9 9999;dsn='';";

cn.Open(strConnection,"","",iOpt);

if(cn.State==Convert.ToInt32(ObjectStateEnum.adSta teOpen))
{
iRet=1;//return1todenoteasuccessfulconnection.
}
}
catch(Exceptionex)
{
iRet=0;
cn=null;
//falseforwritinglogentrytocustomizedtextfile
boolbLogRet=ErrorLog.ErrorRoutine(false,ex);
}
returniRet;
}
</CODE>

This is the entire web service with a minor change to the connection string [to protect the guilty]. The appverurl table has three fields: "Application" varchar(100), "Version" varchar(50), and "URL" varchar(255). I am using ADODB and MySQL (I have uploaded adodb.dll to my bin directory). As you can see I added lots and lots of error checking (which throws the exceptions into a trace file). I don't understand why it randomly works or doesn't. The problem always seems to come in getting the data out of the fields in the recordset. I'm pretty new to this web service/database stuff, so if I should use a different method to connect to the database, I would appreciate some insight.

I'm really at a loss and could use a little direction if any of you are still with me.
Thanks,
sbl

sleonard
04-02-2004, 09:16 AM
I have created two web services on DASP, and neither one of them are working correctly. They are randomly going up and down. I am using C#, ADODB and MySQL. The web service simply executes a select statement on a value passed into the function and returns an array of resultant strings. No one else is hitting these, the databases currently have less than 10 records, and the resultant string arrays are 2 to 5 in length. I am setting the recordset to null and closing the connection after every call. If I run the service locally on my IIS box hitting the same DASP MySQL db, it works all the time, even when the DASP deployed service doesn't. Yesterday, when one of my services was down, it would return an array of two null strings on a hit record, which tells me it was executing the query and finding a record. A no hit query would return an zero length array. The only possible point of failure is here:

[quote]
sData=newstring;
rs.MoveFirst();
sData[0]=HttpUtility.UrlEncode((string)rs.Fields[0].Value);
sData=HttpUtility.UrlEncode((string)rs.Fields.Valu e);
</CODE>

This is in a try catch block and I am not seeing anything from my exception logger.

Any help would be appreciated,
sbl

P.S. As I was typing this, the one that was working for the last 12 hours went down and came back up...

bruce
04-03-2004, 09:51 AM
This means rs.Fields[0].Value is Null. Try check for DBNull before you reference a field.


[b]quote:Originally posted by sleonard

Very lengthy update...
I had a bug in my exception handling/logging code... so I didn't see them.
Now I get this:

Source : mscorlib
Method : get_Keys
Date : 6:09:12 PM
Time : 4/2/2004
Computer : web999
Error : Object reference not set to an instance of an object.
Stack Trace : at System.Runtime.Remoting.Messaging.MessageDictionar y.get_Keys()
at TestVersionService.mxVersion.sArGetVersion(String sAppName) in Z:\YYY\testversionservice.root\testversionservice\ mxversion.asmx.cs:line 100
^^-------------------------------------------------------------------^^

Here is line 100:
[quote]
stringsTemp1=Convert.ToString(rs.Fields[0].Value);
</CODE>

Here is the entire web service:
[quote]
[WebMethod]
publicstring[]sArGetVersion(stringsAppName)
{
//declareavariableoftypeobjecttostorethereturnvaluef romthesqlstatementexecuted.
objectobj=null;

//avariableoftypestringtoreturntheversionassociatedw iththeapplication
string[]sData=newstring[0];
longlRecResult=0;
intiOpt=0;
try
{
iOpt=Convert.ToInt32(CommandTypeEnum.adCmdText);

sAppName=HttpUtility.UrlDecode(sAppName);
//CalliMakeDbConnectiontomakeconnectiontothedatabase
//ifreturnis0,databaseconnectionfailed.
//ifreturnis1,databaseconnectionsucceeded
if(this.iMakeDbConnection()!=0)
{
if(cn!=null)
{
//executeasqlstatementtogetthelatestversionforthisap pName.
rs=cn.Execute("selectVersion,URLfromappverurlwhereApplication='"+sAppName+"'",outobj,iOpt);
lRecResult=Convert.ToInt64(obj);
//Checktheresultoftheabovesqlstatement,return0,ifthe resultiszero,elsecontinue
if(lRecResult>0)
{
if(rs!=null)
{
rs.MoveFirst();
stringsTemp1=Convert.ToString(rs.Fields[0].Value);
stringsTemp2=Convert.ToString(rs.Fields.Value);
if((sTemp1!=null)&&(sTemp2!=null))
{
sData=newstring;
sData[0]=HttpUtility.UrlEncode(sTemp1);
sData=HttpUtility.UrlEncode(sTemp2);
if((sData[0]==null)||(sData==null))
{
if(sData[0]==null)
{
sData[0]="";
}
if(sData==null)
{
sData="";
}
thrownewException("Encodefieldvalueerror.lRecResultwas["+lRecResult.ToString()+"],Recordsetstatewas["+Convert.ToInt64(rs.State).ToString()+"],Recordsetstatuswas["+Convert.ToInt64(rs.Status).ToString()+"],Field0was["+sTemp1+"],Field1was["+sTemp2+"],Encode0was["+sData[0]+"],Encode1was["+sData+"].");
}
}
else
{
if(sTemp1==null)
{
sTemp1="";
}
if(sTemp2==null)
{
sTemp2="";
}
thrownewException("Fieldvalueerror.lRecResultwas["+lRecResult.ToString()+"],Recordsetstatewas["+Convert.ToInt64(rs.State).ToString()+"],Recordsetstatuswas["+Convert.ToInt64(rs.Status).ToString()+"],Field0was["+sTemp1+"],Field1was["+sTemp2+"].");
}
}
else
{
thrownewException("RecordsetwasnullandlRecResultwas["+lRecResult.ToString()+"].");
}
}
else
{
thrownewException("lRecResultwaszero.Couldeasilybe'notfound'onbadinpu t["+sAppName+"].");
}
}
else
{
thrownewException("Connectionwasnull.");
}
}
else
{
thrownewException("Unabletomakedbconnection.");
}
}
catch(Exceptionex)
{
//falseforwritinglogentrytocustomizedtextfile
boolbLogRet=ErrorLog.ErrorRoutine(false,ex);
}
finally
{
rs=null;
if((cn!=null)&&(cn.State!=Convert.ToInt32(ObjectStateEnum.adState Closed)))
{
cn.Close();
}
cn=null;
}
returnsData;
}

//Thisisaprivatefunctiontomakeconnectiontodatabase
//takesnoarguments
//returnvalueisaninteger.0todenoteunsuccessfulconnec tionanda1todenoteasuccessfulconnection
privateintiMakeDbConnection()
{
stringstrConnection="";
intiOpt=0;
intiRet=0;//return0todenoteaunsuccessfulconnection.

try
{
iOpt=Convert.ToInt32(ConnectOptionEnum.adConnectUn specified);
cn=newADODB.Connection();

//createaconnectionstring
strConnection="uid=nunya;pwd=bidness;server=mysql01.discountasp.n et;driver={MySqlODBC3.51Driver};database=MYSQLDB_9 9999;dsn='';";

cn.Open(strConnection,"","",iOpt);

if(cn.State==Convert.ToInt32(ObjectStateEnum.adSta teOpen))
{
iRet=1;//return1todenoteasuccessfulconnection.
}
}
catch(Exceptionex)
{
iRet=0;
cn=null;
//falseforwritinglogentrytocustomizedtextfile
boolbLogRet=ErrorLog.ErrorRoutine(false,ex);
}
returniRet;
}
</CODE>

This is the entire web service with a minor change to the connection string [to protect the guilty]. The appverurl table has three fields: "Application" varchar(100), "Version" varchar(50), and "URL" varchar(255). I am using ADODB and MySQL (I have uploaded adodb.dll to my bin directory). As you can see I added lots and lots of error checking (which throws the exceptions into a trace file). I don't understand why it randomly works or doesn't. The problem always seems to come in getting the data out of the fields in the recordset. I'm pretty new to this web service/database stuff, so if I should use a different method to connect to the database, I would appreciate some insight.

I'm really at a loss and could use a little direction if any of you are still with me.
Thanks,
sbl
</blockquote id="quote"></font id="quote">

sleonard
04-03-2004, 10:13 AM
I gathered that it was null, the problem is it shouldn't be. I am passing in data that returns a hit in the recordset, otherwise the code wouldn't get to the point where it fails. Currently the data in the tables themselves is static. Those fields have data in them. The problem is that depending on whether it wants to or not, for no apparent reason, the data provider has no data in the fields.

sbl

sleonard
04-05-2004, 07:42 AM
At my last post I was in the process of switching over
to the ByteFX MySQL driver. Both web services have been
returning hits now for almost two days with no failures
(using the same queries as before). Unless someone has
another explanation (which I would appreciate), I'll just
chalk it up to "M[Y]*S((QL)|(FT))+ SUX</font id="red">".

Thanks,
sbl

bruce
04-06-2004, 03:51 AM
didn't realize you were using mysql.

the mysql ODBC driver is kinda unstable.


quote:Originally posted by sleonard

At my last post I was in the process of switching over
to the ByteFX MySQL driver. Both web services have been
returning hits now for almost two days with no failures
(using the same queries as before). Unless someone has
another explanation (which I would appreciate), I'll just
chalk it up to [b]"M[Y]*S((QL)|(FT))+ SUX</font id="red">".

Thanks,
sbl
</blockquote id="quote"></font id="quote">