Good Day,
i am trying to write an R code in .net to run as a WCF function. this function is suppose to import a csv file to MSSQL using R using .net code.
I am getting a stackoverflow error when i try to reference the odbc library over wcf, however if i try to run the function using debug instance it passes that point.
public string R_to_MSSQL_Server(string data, string Server, string Database,string Tablename)
{
StartupParameter rinit = new StartupParameter();
rinit.Quiet = true;
rinit.RHome = #"C:\Program Files\R\R-3.4.4\";
rinit.Home = #"C:\R";
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance(null, true, rinit);
StringBuilder Data = new StringBuilder();
Data.Append(data);
string filepath = Path.Combine(Path.GetTempPath(), "RTable.csv");
//"UID= Tester;" +
//"PWD= rstudioapi::askForPassword(\"password\"); " +
try
{
UploadCSV(Data);
filepath = PathCleaning(filepath);
engine.Evaluate("Data <- read.csv(file<- '" + filepath + "', heade= TRUE, sep=',')");
engine.Evaluate("Table <- data.frame(Data)");
engine.Evaluate("connectionString <- ' " +
"driver={SQL Server}; " +
"server= "+ Server + "; " +
"database=" + Database + ";" +
"UID= Tester;" +
"PWD= rstudioapi::askForPassword(\"password\"); " +
"'");
engine.Evaluate("library(odbc)");
engine.Evaluate("library(healthcareai)");
engine.Evaluate("con<- DBI::dbConnect(odbc::odbc(),.connection_string=connectionString)");
engine.Evaluate("DBI::dbwriteTable(conn=con," + Tablename + " , Table)");
return "Completed successfully";
}
catch( Exception x)
{
return "Fail to complete" + x;
}
}
the error when i run it through WCF hits at "engine.evaluate("library(odbc)");"
This is where its being called by another machine accessing it through wcf.
static void Main(string[] args)
{
MainServiceClient client = new MainServiceClient();
string tablename = "Test Table";
string Table = "";
string Pkey ="Name";
Table=File.ReadAllText(#"\\lonvmfs02\Home\kr.williams\TestTable2.csv");
string query = client.R_to_MSSQL_Server(Table, "stage04", "CWDataSets", "Tester");
this is the error thats being thrown inside the WCF Machine ( W3wp debugging ).
System.StackOverflowException
HResult=0x800703E9
Source=
StackTrace:
this is all the exception details give.
how do it increase the size of the stack / get around this problem?
Thanks
Related
I am creating a C# Program to generate a SSIS package, does anyone know how to set the ErrorOutput property of an EzOleDbDestination object to "Redirect Row"?
Edit :
EzOleDbDestination db_dest = new EzOleDbDestination(dataFlow)
{
Name = "Destination " + File_Name,
Connection = oldb_connection,
Table = "[dbo].[" + File_Name + "]"
};
EzOleDbDestination db_dest_clean_error = new EzOleDbDestination(dataFlow)
{
Name = "Destination " + File_Name + "_CleanError",
Connection = oldb_connection,
Table = "[dbo].[" + File_Name + "_CleanError]"
};
db_dest.AttachTo(file_source);
db_dest_clean_error.AttachTo(db_dest);
db_dest.LinkAllInputsToOutputs();
db_dest_clean_error.LinkAllInputsToOutputs();
dataFlow.AttachTo(Sql_Create);
package.SaveToFile("C:\\Users\\LGuerin\\Desktop\\Package_" + Engagement + ".dtsx"); ;
These two lines make it work, Thank you billinkc for your answers!
This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 6 years ago.
Hey guys I have a web application and some times when I publish it to the server it drives me crazy cause it's not loading. It returns an error of System.NullReferenceException: Object reference not set to an instance of an object and it hits on Global.asax Application_BeginRequest (I tried Application_AuthenticateRequest - same result).
Global.asax Application_BeginRequest code:
try
{
HttpRequest request = HttpContext.Current.Request;
string header = request.Headers["X-MicrosoftAjax"];
if(header != "Delta=true")
{
string path = "~/Logs/TrafficAnalytics.txt";
string txt = "Visit from: " + ClientInfo.GetClientIP() + " at: " + ClientInfo.GetClientLastRoute + ". Traceback below:\r\nIP Address: " + ClientInfo.GetClientIP() + "\r\nHostname: " + ClientInfo.GetClientHostname + "\r\nCoordinates: " + ClientInfo.GetClientCoordinates() + "\r\nLocation: " + ClientInfo.GetClientLocation() + "\r\nOS & Browser Info: " + ClientInfo.GetClientBrowserOs + "\r\nBrowser Info: " + ClientInfo.GetClientBrowserInfo() + "\r\nOperating System: " + ClientInfo.GetClientOsInfo() + "\r\nISP: " + ClientInfo.GetClientIsp();
Logger.Create(path, txt);
}
}
catch (Exception ex)
{
HttpContext con = HttpContext.Current;
HttpException code = ex as HttpException;
string bos = Request.UserAgent;
string path = "~/Logs/ErrorReports.txt";
string txt = "URL: " + con.Request.Url.ToString() + "\r\nError Message: " + ex.Message + "\r\nAnalyzed Message: " + ex.ToString() + "\r\nError Code: " + code.GetHttpCode().ToString() + "\r\nIpAddressTraceResult: " + ClientInfo.GetClientIP() + "\r\nOS & Browser Info: " + bos;
Logger.Create(path, txt);
}
Logger.cs source:
using System;
using System.IO;
using System.Web;
public class Logger
{
public static void Create(string p, string t)
{
FileInfo path = new FileInfo(HttpContext.Current.Server.MapPath(p));
string txt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff") + " :::::::::: " + t + "\r\n------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
path.IsReadOnly = false;
StreamWriter sw = new StreamWriter(path.ToString(), true);
sw.WriteLine(txt);
sw.Flush();
sw.Close();
}
}
The error is happening only sometimes it usualy works so I don't know what am I doing wrong. Thanks for all responses...
Well, the best answer is to debug or gather a full stack trace to find which specific line is throwing.
One obvious issue - what if the exception you're catching isn't an HttpException? For example, what if your logging code had an exception in StreamWriter's constructor? It can throw seven different exceptions, none of which are HttpExceptions.
You'd end up in the catch, the value of code would be null because the exception couldn't be cast to an HttpException, and code.GetHttpCode() would throw a NullReferenceException.
For some reason my code just decided to stop working after doing a build and not sure what the issue is.
public class clsSaveError
{
public clsSendEmail.clsSendEmail SendEmail = new clsSendEmail.clsSendEmail();
public clsSettings.clsSEttings Settings = new clsSettings.clsSEttings();
public clsLinqToSQL.K12DataClassesDataContext dbContext = new clsLinqToSQL.K12DataClassesDataContext();
public void InsertErrorIntoDatabase(string monsterID, string dbtable, string errormessage, string stacktrace, EventLog log)
{
clsLinqToSQL.K12DataClassesDataContext dbContext = new clsLinqToSQL.K12DataClassesDataContext();
try
{
dbContext.tblErrors err = new dbContext.tblErrors();
err.monsterid = monsterID;
err.dbtable = dbtable;
err.errormessage = errormessage;
err.stacktrace = stacktrace;
dbContext.tblErrors.Insertonsubmit(err);
dbContext.SubmitChanges();
}
catch (Exception except)
{
//write the error to the event log
log.WriteEntry("ERROR! Unable to write error to database. Here are the details:" + "\n" +
"Exception Message: " + except.Message + "\n" +
"Exception Stacktrace: " + except.StackTrace + "\n" +
"Database Error Details: " + "\n" +
"Monster ID: " + monsterID + "\n" +
"Database Table: " + "\n" +
"Error Message: " + "\n" +
"Stacktrace: " + stacktrace);
SendEmail.SendEmail(Settings.mailport, Settings.mailhost, Settings.mailtimeout, Settings.mailusername, Settings.mailpassword, Settings.mailfrom, Settings.mailto, "Database Error - Unable to update Error Log", "Message: " + except.Message + "\n" + "Stacktrace: " + except.StackTrace);
}
}
}
The error is:
'clsSaveError.clsSaveError.dbContext' is a 'field' but is used like a 'type'
I know this is a generic error but I am not sure why it is occurring now. Thanks for the input!
You're declaring a variable here:
clsLinqToSQL.K12DataClassesDataContext dbContext = new clsLinqToSQL.K12DataClassesDataContext();
Then trying to use that variable as a type here:
dbContext.tblErrors err = new dbContext.tblErrors();
If dbContext is the name of a type, don't declare variables by the same name. If it isn't the name of a type, then I have no idea what the above line of code is trying to do.
Your type names and variable names are entirely breaking C# conventions, making the code difficult to read. For example:
public clsSendEmail.clsSendEmail SendEmail = new clsSendEmail.clsSendEmail();
Your type names are lowercase, and your variable is uppercase. This is backward from standard convention. Prepending cls to every type name isn't helping.
The situation:
I want to modify the folder quotas on my FileServer through a process executing dirquota.exe
The Problem:
The Process being executed gives no result at all
So Far:
I've redirected the process and arguments being executed on my FileServer to take a closer look what's happening exactly on the serverside.
The executed process gave no exception and everything went just fine, it seemed..
When looking at the current folder quota's on my FileServer nothing has changed..I decided to copy paste my arguments in a CMD.exe on the server, then it all went fine...
I cannot figure why it is not working on my FileServer, probably somthing simple but I need some help here
Important Info:
I'm installing a Windows Service on my FileServer and calling the Method through SOUPUI (This is all working fine).
The installed service is running as a Domain admin and has all the required rights to perform these actions
The Class
public class Quota
{
public string FolderLocation;
public int SizeInMB;
public string FileServerName;
}
The Method
public string SetFolderQuota(Quota quota)
{
Process QuotaProcess = new Process();
QuotaProcess.StartInfo.RedirectStandardOutput = false;
QuotaProcess.StartInfo.FileName = #"cmd.exe";
QuotaProcess.StartInfo.UseShellExecute = true;
QuotaProcess.StartInfo.Arguments = "/C " + "dirquota Quota Add /PATH:" + '"' + quota.FolderLocation + '"' + " /Limit:" + quota.SizeInMB + "mb" + " /remote:" + quota.FileServerName;
try
{
QuotaProcess.Start();
}
catch(Exception Ex)
{
return Ex.Message;
}
return "Correctly Executed: " + QuotaProcess.StartInfo.FileName + QuotaProcess.StartInfo.Arguments;
}
Found The Problem
dirquota.exe is redirected using Windows-on Windows 64-bit redirection. What's happening is that my launch request (from a 32-bit process) is being redirected to %windir%\SysWOW64\dirquota.exe. Since there's no 32-bit version of this particular executable on 64-bit installs, the launch fails. To bypass this process and allow my 32-bit process to access the native (64-bit) path, I have to reference %windir%\sysnative instead
The Code
public string SetFolderQuota(Quota quota)
{
string FileLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),#"sysnative\dirquota.exe");
Process QuotaProcess = new Process();
QuotaProcess.StartInfo.RedirectStandardOutput = false;
QuotaProcess.StartInfo.FileName = FileLocation;
QuotaProcess.StartInfo.UseShellExecute = true;
QuotaProcess.StartInfo.Arguments = " Quota Add /PATH:" + '"' + quota.FolderLocation + '"' + " /Limit:" + quota.SizeInMB + "mb" + " /remote:" + quota.FileServerName;
try
{
QuotaProcess.Start();
}
catch(Exception Ex)
{
return Ex.Message + Environment.NewLine + "FileLocation: " + FileLocation;
}
return "Correctly Executed: " + QuotaProcess.StartInfo.FileName + QuotaProcess.StartInfo.Arguments;
}
Best if you can redirect the output of Process to a log file and see what is the actual exception..
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = #"cmd.exe",
Arguments = "/C " + "dirquota Quota Add /PATH:" + '"' + quota.FolderLocation + '"' + " /Limit:" + quota.SizeInMB + "mb" + " /remote:" + quota.FileServerName
};
Process p = Process.Start(process);
string output = p.StandardOutput.ReadToEnd();
Log the value of output to get the exact exception caused by execution of this command
The following is used when
int topicOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
MQTopic mqTopic = qmgr.AccessTopic(mqCloneSpecs.topicString, "",
MQC.MQTOPIC_OPEN_AS_PUBLICATION, topicOptions);
The above part of the program builds a list of QueueManagers and a list of Topics which are used to call a listener class in a Windows service.
int tLoopCounter = 0;
foreach (MQTopic topic in topicOut)
{
tLoopCounter++;
// NOTE: We blow up here with 2019 MQRC_HOBJ_ERROR if we access the property topic.Name
//Console.WriteLine("Loop through topics topic.IsOpen: " + topic.IsOpen);
//Console.WriteLine(" OpenOptions:" + topic.OpenOptions);
debugLocation = "4053";
Console.WriteLine(" OpenStatus=" + topic.OpenStatus);
debugLocation = "4054";
i = tLoopCounter - 1;
Console.WriteLine("i=" + i);
debugQueueInfo = " topicPut #" + tLoopCounter + " QueueMgr:" + queueManagerForTopicsOut[i].Name.TrimEnd();
// currently getting 2019 : MQRC_HOBJ_ERROR on the line below
debugLocation = "4055";
debugQueueInfo += "Topic:" + topic.Name;
Console.WriteLine("Pump:Topic.Put:" + debugLocation + ":" + debugQueueInfo);
debugLocation = "4057";
topic.Put(mqMessage);
Console.WriteLine("Pump:Topic.Put completed");
}
When I try to add the Inquire option, as shown here:
int topicOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE;
then I die with this error:
DebugLocation=Q3012 Exception: System.ApplicationException:
MQException in Acce ssQueue ---> IBM.WMQ.MQException:
MQRC_OPTIONS_ERROR
Also, the OpenStatus=True from the Console.WriteLIne at debugLocation=4053. My first thought that if it were closed, that would cause this error.