Execute .exe in SSRS Report - sql

i want to execute a .exe in a SSRS Report from Microsoft Dynamics AX.
I tried so far to realize that over Custom Code and a Textfield with following Expression: =Code.StartProcess("test")
Public Function StartProcess(ByVal s As String) As String
Dim pHelp As New ProcessStartInfo
pHelp.FileName = "test.bat"
pHelp.Arguments = s
pHelp.UseShellExecute = True
pHelp.WindowStyle = ProcessWindowStyle.Normal
Dim proc As Process = Process.Start(pHelp)
Return "it works"
End Function
I get the error ":StartProcess is invalid. InvalidIdentifier"
As second try i use this:
="javascript:void(window.open('file://AX2012R2A/Share/batch.exe'))"
in an action expression.
This trial opened in the report the following message by clicking on the image:
My problem is now that I have to pass a parameter to the batch and then it doesn't work.
Have you any idea to help me?

I have solved my Problem.
As first step I mentioned, that also simple methods like:
Public Function StartProcess(ByVal s As String) As String
Return "it works"
End Function
brought the error: ":StartProcess is invalid. InvalidIdentifier"
As second step i found this link:
Link to Google Group discussion
(perhabs you have to expand all messages).
As last step i have to create a Datamethod and then call it in an expression and it works.
The code in the datamethod isn't in VB.Net but in C#.
How this works, can you see here (Youtube)
Thank you all for your help.

Related

Receiving an error from trying to make a startup program shortcut

I am trying to make a shortcut for my program so that it starts automatically with windows. The following code is the sub that creates the shortcut and how it gets it's variables but it fails.
Dim ShortCutPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup) & "/ScreenRot.lnk"
Shared Sub CreateShortCut(File As String, ShortCutPath As String)
Dim oShell As Object
Dim oLink As Object
'you don’t need to import anything in the project reference to create the Shell Object
Try
oShell = CreateObject("WScript.Shell")
oLink = oShell.CreateShortcut(ShortCutPath)
oLink.IconLocation = File
oLink.TargetPath = File
oLink.Arguments = ""
oLink.WindowStyle = 1
oLink.Save()
Catch ex As Exception
End Try
End Sub
The line it seems to fail on is.
oLink = oShell.CreateShortcut(ShortCutPath)
The error I am getting is
DirectCast(ex, System.MissingMemberException).Message
Public member 'CreateShortcut' on type 'IWshShell3' not found.
I am using this in my program.
Imports IWshRuntimeLibrary
I have tried a couple different ways to make the shortcut but this seems to be the one that should work for what I need. I've read a bit about using this code and watched a video but nothing talks about the error. I've googled the error but nothing resembles a solution. I've tried to adjust the code slightly by using other examples but it still fails with more or less the same error. I don't really understand what the error is saying, so I can try and figure it out. thanks for your time and any help you guys can give.
After reviewing many posts and trying a lot of different things I found a solution on Stackoverflow which I can confirm actually works.
Stackoverflow Post
This post has the solution, hopefully it helps other people with this problem.

vb.net Ignore stepping through certain functions when using F5

When I use the debugger and F5 to follow along what is currently being called in my app, I have some functions which I don't want the debugger to go through.
These functions are not important to me, and I know what they are doing. Having the debugger step through each line of this function is just taking my time.
How could I make it so that the debugger ignores the function?
Thank you!
With the help of #Jimi, I found a VB.net solution.
One has to add
<DebuggerStepThrough()>
over the first line of the function.
For example:
<DebuggerStepThrough()>
Public Function StrLen(ByVal uString As String) As Integer
If (Not uString Is Nothing) AndAlso (Not uString = String.Empty) Then
Return uString.Length
Else
Return 0
End If
End Function

VB.NET GetProcessesByName method is missing

I'm building a program in VB whose purpose is to run in the background and automatically update other programs I've created. To do this, it has to check if those programs are still running and, if they are, wait for them to close.
Unfortunately, the program won't compile. The exception states: GetProcessesByName is not a member of String. (The string it refers to is the Process parameter shown in the code below.)
I can't understand why this is happening, because this method has always worked without problems. I'm using Visual Studio 2015. For your reference, here's the code block:
Private Function CheckIfRunning(Process As String) As Boolean
Dim MyProcess() As Process
MyProcess = Process.GetProcessesByName("ProcessName")
If MyProcess.Count > 0 Then
Return True
Else
Return False
End If
End Function
Try using System.Diagnostics.Process.GetProcessesByName("ProcessName")
Since you've declared Process as a string parameter, Process.GetProcessesByName refers to the string instead of the System.Diagnostics method. Alternatively, you can use a different name for the string parameter.

VB.Net Report viewer parameters

I added a Parameter to report.rdlc called "ReportTitle". It is text and allows blank values and nulls. I have tried different ways to pass the parameter value to no avail. This is what I've tried so far:
Dim parReportParam1 As New ReportParameter("ReportTitle", "THIS IS MY TITLE")
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {parReportParam1})
Does not work!
Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
params(0) = New Microsoft.Reporting.WinForms.ReportParameter("ReportTitle", "THIS IS MY TITLE")
ReportViewer1.LocalReport.SetParameters(params)
Nothing!
Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
params(0) = New Microsoft.Reporting.WinForms.ReportParameter
params(0).Name = "ReportTitle"
params(0).Values.Add("THIS IS MY TITLE")
ReportViewer1.LocalReport.SetParameters(params)
Nope!
I don't know what to try anymore. Do I have to set something on the reportviewer or on the designer to allow parameter values. Any help is greatly appreciated it.
I found The Aswer, You need to remember to put parameters after you pick the path to the Report never before.
I had exacly the same problem, everything was fine till I put parameters to the Raport and I had spent two hours before I found the cause.
This worked for me:
Dim paramStoreNo As New ReportParameter("StoreNo", iSTORE_NO)
Dim reportparameters() As ReportParameter = {paramStoreNo}
InventoryTableAdapter.Fill(Me.DataSet1.Inventory, iSTORE_NO)
Me.ReportViewer1.LocalReport.SetParameters(reportparameters)
Me.ReportViewer1.RefreshReport()
Maybe accidentally you have set available values for parameter to just null or some other values in report.rdlc. If so goto parameter properties and set Available Values to None and try again.
If your problem is that you cant see your parameter value at your report, Can you try adding a refresh in your report viewer code page.
Add this at the end of your code
Reportviewer.localreport.refresh()
The problem might be because the page loaded before the application finished passing the values, so refresh it so it can reload with the parameter values at hand.
I used the following code and it works fine:
For Each param As WinForms.ReportParameterInfo In ReportViewer1.LocalReport.GetParameters()
If param.name = "ReportTitle" Then
ReportViewer1.LocalReport.SetParameters(New WinForms.ReportParameter(param.Name, "THIS IS MY TITLE"))
End If
Next
Me.ReportViewer1.RefreshReport()

VB.Net calling New without assigning value

In C# I can do this:
new SomeObjectType("abc", 10);
In other words, I can call new without assigning the created instance to any variable. However, in VB.Net it seems I cannot do the same thing.
New SomeObjectType("abc", 10) ' syntax error
Is there a way to do this in VB.Net?
The following works on the Mono VB compiler (vbnc, version 0.0.0.5914, Mono 2.4.2 - r):
Call New SomeObjectType("abc", 10)
Notice the required Call.
See the answers to this other SO Answer
So this should work:
With New SomeObjectType("abc", 10)
End With
One can define a Sub to discard the constructed object:
Sub gobble(dummy As Object)
End Sub
Then call the constructor as follows:
gobble(New SomeClass())
I'm using this approach in tests when I test exceptions in constructors. I construct the object in a lambda and pass that lambda to a function that checks for the Exception. Fits nicely on a line.
assertThrows(Of ArgumentOutOfRangeException)(Sub() gobble(New ClassUnderTest("stuff")))
That should be the correct syntax, e.g.
Dim name As New String
Dim url As New Uri("http://www.somedomain.com")
Have you got some more code where this is happening?