Click to See Complete Forum and Search --> : C# Web Method to C++ MFC Client - Problem with SqlException exception


b1965
December 30th, 2002, 12:32 PM
Dear Code Guru!
I have a problem with sending back the string in Web
Method.
I have C# ASP web service which has the following Web
Method:
Method connects with "job" db on MS SQL Server

public class CWS_SQL_QUERY :
System.Web.Services.WebService
{
. . .
[WebMethod]
public string GetXMLDataSet()
{
string strCon="";
strCon="data
source=ASD;initial
log=pubs;integrated
security=SSPI;persist
security
info=False;workstation
id=ASD;packet size=4096";

SqlConnection con=new
SqlConnection(strCon);
try
{

con.Open();
}
catch (SqlException e)
{
return e.Message;

}

con.Close();
return "OKAY";
}

AND MFC C++ Application which calls the method from
Client in the following code:

CCWS_SQL_QUERY service;
CComBSTR bstrResponse;
HRESULT hr = service.GetXMLDataSet(&bstrResponse);


Everything works without any problem when SQL Server is
up.
I always received "OKAY" string.
The problem appears when I stop SQL Service Manager.
I catch SqlException in the block above and suppose to
send the string (e.Message) back to client.
When I am going through by debugger I can see that it
does it, as you can see below.
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">SQL Server does not
exist or access denied.</string>

However the C++ statement:
HRESULT hr = service.GetXMLDataSet(&bstrResponse);
bstrResponse is empty ( <Bad Ptr> ).
Serice.m_fault (fault element) does not have this string
and any error descriptions as well.
Hr = E_FAIL

I appreciate if any body can explain WHY IS IT?
Please notice that if I create and initiate exeption it
works without problems.
I already tried the following in C# ASP:
1. this.Server.ClearError();
2. Create an exception and fill the fault element and
throw the exception.
All that did not change anything.
Please help.

Thank you in advance!
Boris