Lightswitch Stored procedure - stored-procedures

This is my stored procedure
Using connection = New SqlConnection
' Dim connectionStringName = Me.DataWorkspace.XtraReportsServiceData.Details.Name
connection.ConnectionString = "Data Source=WIN-BTU6KNHNEGR\SQLEXPRESS;Initial Catalog=SapyLiveSystem;User ID=sa;Password=tytyty#21;Connection Timeout=3000000;"
Dim procedure = "UpdateColorMatching"
Using command = New SqlCommand(procedure, connection)
command.CommandType = CommandType.StoredProcedure
connection.Open()
command.ExecuteNonQuery()
End Using
End Using
'result = webservicesql.CallStoredProcuder
Log.log("Called after Stored Procedure")
It runs 100% on my development pc and if I call the stored procedure from a web service it runs 100% if I install it on the server and try and call that procedure from a webservice through light switch it wont run. If I call the webservice it runs 100% fine. If I run from lightswitch on development pc it works 100% fine buy not from server any help

Related

Is it possible to upload file on server using scheduler or windows service?

I am trying to do file upload using quartz job scheduler. but, it is not working.
Is it possible to upload file to the server using job or windows sevice.
I have googled but not understand much. please provide some link for reference.
It is possible to upload file using windows service i guess. We build a similar kind of windows service for inserting to database recursively.[1]: https://www.c-sharpcorner.com/article/create-windows-services-in-c-sharp/
protected override void OnStart(string[] args)
{
WriteToFile("Service is started at " + DateTime.Now);
Fileupload();
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 1000*60*60*10; //number in milisecinds
//timer.Interval = 1000 * 60;
timer.Enabled = true;
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
Fileupload();
WriteToFile("Service is recall at " + DateTime.Now);
}
//you can use the above 2 functions in Serivce Cs file and you define your Custom Fileupload Function for uploading file. Hope this works for you

Windows service not executing after first run

I have create a windows service in VS 2010. I install it and also run it at the same time and set startup type to Automatic . I see it running fine through EventViewer and is successfully completed.
But after that i done see EventViewer showing anything, even if the work is doen it still should check DB and skip as all rows done.
So what is the issue ?
DO i need to make it an infinite loop in the service to keep it running?
Something like
While (ROWs in DB ! = null) ?
Because it does not seem it is working like task scheduler!
Yes, you need to do a loop with the possibility to break it again. Example service (VB.NET):
Public Class MyService
Protected Property IsRunning As Boolean = False
Protected Sub OnStart(args() As String)
IsRunning = True
' make the loop function run asynchronously
Dim t As New System.Threading.Thread(AddressOf MyLoopFunction)
t.Start()
End Sub
Protected Sub MyLoopFunction
While IsRunning
' here comes your code ...
' sleep for a second for better CPU freedom
System.Threading.Thread.Sleep(1000)
End While
End Sub
Protected Sub OnStop()
IsRunning = False
End Sub
End Class

Open exe as service without "Interactive Service Detection" message in window 7

I have a simple application that watches a folder for any changes as following:
private void Form1_Load(object sender, EventArgs e)
> {
> FileSystemWatcher w = new FileSystemWatcher();
> w.Path = #"C:\temp";
> w.Changed += new FileSystemEventHandler(OnChanged);
> w.Created += new FileSystemEventHandler(OnChanged);
> w.Deleted += new FileSystemEventHandler(OnChanged);
> w.Renamed += new RenamedEventHandler(OnChanged);
> // Begin watching.
> w.EnableRaisingEvents = true;
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType + Path.GetFileName(e.FullPath));
}
I added the same as service from the command prompt as
sc create <service name> binPath= <path of the exe file>
This added the exe in the services and also made the entries in Registry. But when I tried to start the service as
sc start <service name>
it showed up the "Interactive Service Detection" message.
I want to avoid this message from popping up and start the service.
I also need this to be done in c# but if anyone has any idea about doing it in cmd I can add it as a batch file and execute the same.
EDIT I
As #Seva suggested I created a service that calls the exe that I wish. I wrote the following code to start the exe on start of the service:
protected override void OnStart(string[] args)
{
base.OnStart(args);
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
p.StartInfo.CreateNoWindow = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.WorkingDirectory = #"<my exe path>";
p.StartInfo.FileName = "<myexe.exe>";
p.StartInfo.Arguments = #"<my exe path>";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.WaitForExit();
base.Stop();
}
I installed the service successfully but is not starting the exe on starting.
EDIT II
The exe started. The service's property had to be configured to allow service interaction with desktop, but then again the "Interactive service detection" message is coming up.
You will have to rearchitecture your windows service into two parts -- a GUI-less service process and a separate UI app that runs on user desktop. There are many ways service can communicate with UI app. These SO questions will get you started:
GUI and windows service communication
Communication between windows service and desktop app
There is no other way around. BTW, your existing approach is already broken -- for Non-admin users and for remote desktop sessions -- they won't see UI from a service even if they want to.

Run a process on ASP.NET MVC

I'm new on MVC!
I want to run a process on my web app (not for bad purpose), this process can do something, for example it can write a text to a file .txt!
On my local PC, it work well but when I publish it on to host provider, it not work!
How I can do this?
This is my code:
string path = HttpContext.Current.Server.MapPath("~/App_Data/ModuleMaple/ModuleMaple.exe");
Process myproc = new Process();
myproc.StartInfo.FileName = path;
myproc.StartInfo.Arguments ="some argument"
myproc.StartInfo.UseShellExecute = false;
myproc.Start();
myproc.WaitForExit();

How to retain service settings through InstallShield upgrade install

I have an InstallScript project in IS2010. It has a handful of services that get installed. Some are C++ exes and use the "InstallShield Object for NT Services". Others are Java apps installed as services with Java Service Wrapper through LaunchAppAndWait command line calls. Tomcat is also being installed as a service through a call to its service.bat.
When the installer runs in upgrade mode, the services are reinstalled, and the settings (auto vs. manual startup, restart on fail, log-on account, etc.) are reverted to the defaults.
I would like to save the service settings before the file transfer and then repopulate them afterward, but I haven't been able to find a good mechanism to do this. How can I save and restore the service settings?
I got this working by reading the service information from the registry in OnUpdateUIBefore, storing it in a global variable, and writing the information back to the registry in OnUpdateUIAfter.
Code:
export prototype void LoadServiceSettings();
function void LoadServiceSettings()
number i, nResult;
string sServiceNameArray(11), sRegKey, sTemp;
BOOL bEntryFound;
begin
PopulateServiceNameList(sServiceNameArray);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
//write service start values to the registry
for i = 0 to 10
if (ServiceExistsService(sServiceNameArray(i))) then
sRegKey = "SYSTEM\\CurrentControlSet\\Services\\" + sServiceNameArray(i);
nResult = RegDBSetKeyValueEx(sRegKey, "Start", REGDB_NUMBER, sServiceSettings(i), -1);
if(nResult < 0) then
MessageBox ("Unable to save service settings: " + sServiceNameArray(i) + ".", SEVERE);
endif;
endif;
endfor;
RegDBSetDefaultRoot(HKEY_CLASSES_ROOT); //set back to default
end;
export prototype void SaveServiceSettings();
function void SaveServiceSettings()
number i, nType, nSize, nResult;
string sServiceNameArray(11), sRegKey, sKeyValue;
begin
PopulateServiceNameList(sServiceNameArray);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
for i = 0 to 10
if (ServiceExistsService(sServiceNameArray(i))) then
//get service start values from registry
sRegKey = "SYSTEM\\CurrentControlSet\\Services\\" + sServiceNameArray(i);
nResult = RegDBGetKeyValueEx(sRegKey, "Start", nType, sKeyValue, nSize);
if(nResult < 0) then
MessageBox ("Unable to save service settings: " + sServiceNameArray(i) + ".", SEVERE);
endif;
sServiceSettings(i) = sKeyValue;
endif;
endfor;
RegDBSetDefaultRoot(HKEY_CLASSES_ROOT); //set back to default
end;

Resources