Click here to Skip to main content
15,888,202 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I call R script method from Web API it is working for first request it returns the result, but for subsequent request getting Stack overflow exception.
The same code is working on another system, tried desposing all the objects in the R.

Please help me to sort out this issue.

Using
R 3.4.2
Version.

What I have tried:

WebAPI Method calling R Script:
<pre>Public HttpResponseMessage CallTestMethod()
{
// SetupPath(); setting Rpackage and ODBC package paths in environment no issue with this method.
REngine engine;
engine = REngine.GetInstance();
//Mentioned R Script file path
var val = engine.Evaluate("source('C:/Folder/RProject1/Script.R')");
//Call FetchDatawithoutParam () and get data frame values in dsResult .
var dsResult = engine.Evaluate(@"TempDataResult <- FetchDatawithoutParam ()").AsDataFrame();
}


R Script function as below:
FetchDatawithoutParam <- function() {

    dbConnection <- odbcDriverConnect('driver={SQL Server};server=.;database=DBName;trusted_connection=true')
    DataResult <- sqlQuery(dbConnection, "SELECT * FROM TableName;")
   odbcClose(dbConnection)
 return(DataResult );
}
Posted
Updated 11-Mar-18 22:45pm
v3
Comments
Jochen Arndt 12-Mar-18 4:31am    
I don't know if this might be the reason for your problem but the
odbcClose(dbConnection)
call is never executed because you are returning from the function in the previous line.
[no name] 12-Mar-18 4:44am    
changed code still issue persist.
Jochen Arndt 12-Mar-18 6:25am    
Therefore I write is as comment and not as solution.

How large is your returned data set?
It might be too large on specific systems initially and also on other systems when the previous instance has not been disposed when executing the query again.
[no name] 12-Mar-18 8:36am    
It is not working even after I selected top 2 rows from the table.
Also tried by getting result from stored procedure with ODBC connection, No luck.
Jochen Arndt 12-Mar-18 8:40am    
Then it is most probably a recursive call (a function calling itself) as mentioned in the comment by F-ES Sitecore.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900