on 04-15-2007 3:25 PM
I am developing an asp.net application that loads information from our CRM system and presents it to the user.
I want set up the connection and load the data as the page is being set up.
The trouble is, if I put the .OpenSAPConnection call in the Page_Load event, it seems to start the entire page even cycle all over again after the load even completes ...
ex. if I put it in the Page_Load event, as soon as this event completes the Page_Init is fires again, followed by the Page_Load event (again) ... resulting in an infiite loop. I suspect this is the result of trying to write the connection to the viewstate before it is create.
Where can I put the connection given that I want load the data into the page controls before the rendering event fires???
-Sheldon
Hi Sheldon,
how are you doing ?
Page_Load is invoked everytime after a server side event
[loading is part of rendering the page and is literally done everytime]
it would be simpler if you moved your page load control logic to a separate private function :
loadMyPageControls()
this can be placed within the Page_Load function with the check on the IsPostBack flag
if (!IsPostBack)
{
// only if the page is loading for the first time
loadMyPageControls();
}
the first time the page is loaded, the viewstate contains all the added controls (with control.ViewState=true), but the values are not yet initialized. subsequently they become available on each subsequent postback
as per your experience, if the open SAP connection for a proxy is in the Page_Load, it will open the connection(s) on every page load & server side event, and will unnecessarrily overload your application with calls that get the same information repeatedly
with respect,
amit
Message was edited by:
amit chawathe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit!
Thanks for looking at this. It has (and continues (see below)) baffle me.
I had already tried something similar to what you suggested but thought there might be something I had missed, so adjusted the code as per your suggestion .
Here is a simplified version of what I am doing
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadControls();
}
}
.
.
protected void LoadControls()
{
// estabilish connection
try
{
SAP.Connector.SAPLoginProvider.OpenSAPConnection(this, "CLIENT=510 USER=dotnet1 PASSWD=CWD7WGF2 ASHOST=TORCRMQ1 SYSNR=0", false);
}
catch (System.Exception ex)
{
// report errors in connection
}
// read test information
ReadUserInformation("jmichaels12@test.ca");
ReadSubscriptionForUser(UserInformation.CustomerID);
// bind data to controls
rptCurSubscriptions.DataSource = colSubscriptions;
rptCurSubscriptions.DataBind();
}
What happens is that the first time through the exection goes into the !IsPostBack, the controls are loaded as you would expect. The page_load then conpletes as expected but emediately is reentered and <u>goes back into the !isPostBack and loads the controls again</u> ... this continues forever. ie. it doesn't appear to be a post-back but seems to be opening up a whole new page!
The only way I have been able to get it to work is to add a button on the page to initiate the connection and load from a click event, which wont be practical in the final version.
Very strange! If you think of anything I may have missed please let me know.
Hi Sheldon,
after reading your code, a few thoughts come to mind
is there any specific reason you are explicitly calling OpenSAPConnection ?
as per the class doculentation it is used internally, it is sufficient for you to get the connection :
proxy.Connection = SAP.Connector.SAPLoginProvider.GetSAPConnection(this);
with respect,
amit
http://help.sap.com/saphelp_nw04/helpdata/en/8f/3de39b752d284b98b25bad8c8d6b90/content.htm
when you open a connection, it should be assigned to a proxy class to be able to consumed
also once you are done with the connection a close should be incorporated
the connection is to be specific to a proxy, and it is a good practice when you close it when you do not need it
i use connection pooling as well :
e.g.
SAP.Connector.Connection con2SAP;
con2SAP = myConnector.conEstablishConnection(strConnection);
if (con2SAP != null)
{
SAPProxyUserDetails prxUserProxy = new SAPProxyUserDetails();
BAPIRETURN brtUserDetails = new BAPIRETURN();
ZUSERLIST zpsUserList = new ZUSERLIST();
ZUSERLISTTable zptUserList = new ZUSERLISTTable();
try
{
con2SAP.Open();
prxUserProxy.Connection = con2SAP;
prxUserProxy.Z_Portal_Get_User_Details(strUserDomain, strUserName, out strRetDomain,out strExUser, out strFullName, out brtUserDetails,out strRetUserName,out strUserType, out strVendorId, ref zptUserList);
// check if details were retrieved and process results
}
catch (Exception ex)
{
string strError;
strError = ex.Message.Trim();
}
finally
{
if (con2SAP.IsOpen)
{
// close connection
con2SAP.Close();
}
}
where :
public SAP.Connector.Connection conEstablishConnection(string strConnection)
{
SAP.Connector.Connection conReturn;
conReturn = null;
if(strConnection.Trim() !="")
{
conReturn = SAP.Connector.SAPConnectionPool.GetConnectionFromPool(strConnection);
}
return conReturn;
}
public void conReturnConnection(SAP.Connector.Connection con2Return)
{
if(con2Return !=null)
{
con2Return.PrepareForPooling();
SAP.Connector.SAPConnectionPool.ReturnConnection(con2Return);
con2Return = null;
}
}
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.