RS.exe subscribe report with parameters - vb.net

I am trying to create dynamic report subscriptions through rs.exe. How ever I cannot get the parameters to work. The enddate value is data/time, so I think that might be causing it, but I do not know what to do about it. I have tried casting, but the error msg. stays the same.
rs.exe call:
C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn>rs.exe -i C:\Users\me\Desktop\rss_gen\subs.rss -s "localhost/ReportserverT"
subs.rss file:
Public Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim desc As String = "Report description"
Dim eventType As String = "TimedSubscription"
Dim scheduleXml As String = "<ScheduleDefinition><StartDateTime>2017-12-08T15:00:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Thursday>True</Thursday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>"
Dim parameters() As ParameterValue
' If you need setup parameters
Dim parameter As ParameterValue
parameter.Name = "enddate"
parameter.Value = "2017-12-30 10:03:01.250" 'this is date/time
parameters(0) = parameter
Dim matchData As String = scheduleXml
Dim returnValue As String
Dim reports() As String = { _
"/My Folder/report"}
For Each report As String In reports
returnValue = rs.CreateSubscription(report, parameters)
Console.WriteLine(returnValue)
Next
End Sub 'Main`enter code here`
Error msg:
C:\Users\mee\AppData\Local\Temp\11\dhexge0m.1.vb(43) : error BC30455:
Argument n ot specified for parameter 'Parameters' of 'Public Function
CreateSubscription(R eport As String, ExtensionSettings As
Microsoft.SqlServer.ReportingServices2005. ExtensionSettings,
Description As String, EventType As String, MatchData As Stri ng,
Parameters() As
Microsoft.SqlServer.ReportingServices2005.ParameterValue) As String'.

Let me teach you a trick to program in .Net and in general. It sounds simple, all you need to do is pass functions what they expect. Let me give you a simple example.
With this code I've got a similar error to you:
CS7036 There is no argument given that corresponds to the required formal parameter 'fileName' of 'FileInfo.FileInfo(string)'
The squiggle red line tells you where the problem is. If I type the opening bracket it will give me a tooltip with what it expects:
Ok it needs a string, so I declare a string and give it to the function as it expects:
So the problem you have is because you are not giving the CreateSubscription function the parameters it expects.
Argument not specified for parameter 'Parameters' of 'Public Function CreateSubscription
To fix it provide all the mandatory parameters to the ReportingService2005.CreateSubscription Method:
public static void Main()
{
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string report = "/SampleReports/Employee Sales Summary";
string desc = "Send email to anyone#microsoft.com";
string eventType = "TimedSubscription";
string scheduleXml = #"<ScheduleDefinition><StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>";
ParameterValue[] extensionParams = new ParameterValue[8];
extensionParams[0] = new ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "dank#adventure-works.com";
extensionParams[1] = new ParameterValue();
extensionParams[1].Name = "ReplyTo";
extensionParams[1].Value = "reporting#adventure-works.com";
ParameterValue parameter = new ParameterValue();
parameter.Name = "EmpID";
parameter.Value = "38";
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = parameter;
string matchData = scheduleXml;
ExtensionSettings extSettings = new ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";
try
{
rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameters);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
}

As part of the 2005 report service for ms SQL, none of the parameters passed to CreateSubscription are optional. Please refer to the link and update the way you are calling the function. The error is clear, you are missing the parameters which is the last one. Look at the bottom of the page for an example.
https://technet.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsmanagementservice2005.reportingservice2005.createsubscription(v=sql.90).aspx

Related

Error when creating a List object in VB.Net

I am new to .Net framework and I am getting an error message
Value of type 'List(Of AdminSetEmployeeParams)' cannot be converted to
'AdminSetEmployeeParams'"
Dim SetNewEmployee As New List(Of AdminSetEmployeeParams)
SetNewEmployee.Add(New AdminSetEmployeeParams With {
.departmentId = ddlDept.SelectedValue,
.familyName = txtLastOrSurname.Text,
.firstName = txtFirstOrGivenName.Text,
.secondName = txtSecondName.Text,
.contactPhone = txtPhone.Text,
.user = ""})
SetNewEmployee = EmployeeAPIService.AdminSetEmployee(SetNewEmployee).Result
How would I resolve this error?
Update:
System.Threading.Tasks
Public Class Task(Of TResult)
Public ReadOnly Property Result As TResult
It's probably this, but it's hard to be sure:
Dim newEmployee As New AdminSetEmployeeParams
newEmployee = New AdminSetEmployeeParams With {
.departmentId = ddlDept.SelectedValue,
.familyName = txtLastOrSurname.Text,
.firstName = txtFirstOrGivenName.Text,
.secondName = txtSecondName.Text,
.contactPhone = txtPhone.Text,
.user = ""})
Dim newEmployeeResult As List(Of AdminSetEmployeeParams) = EmployeeAPIService.AdminSetEmployee(newEmployee).Result
I'm not sure why your API returns a list of employees in its result (I'm assuming it does because you don't say you have an error message complaining about the assignment of the result to a list(of...) ) but the error as given would reasonably only occur if the API call demanded a single new employee and you handed it a list of new employees
If it doesn't work out, try this last line
Dim newEmployeeResult As AdminSetEmployeeParams = EmployeeAPIService.AdminSetEmployee(newEmployee).Result
And if that doesn't work out, edit your question to give more info on what kind of arguments AdminSetEmployee takes and what kind of object .Result is

Set statement, return empty string if error

From the following link there is an example at the bottom of the page which I have recreated in vb.net.
Before the following function runs, I save some data from a textfile into a dictionary called T.
For example:
Name - T0962
Value - 5.89
Public Shared Function initialization()
'Variables initialization
Dim parts As New List(Of Intialization)
'Add parts to the list.
parts.Add(New Intialization() With {
.PartName = "T0962",
.PartId = T.Item(.PartName))
})
If parts.Exists(Function(p) p.PartName = "T0962") Then
Dim value = parts.Where(Function(p) p.PartName = variable_type).FirstOrDefault()
Msgbox(value.PartId)
End If
End Function
The program works perfectly when I have "T0962" variable. When that variable does not exist in the textfile, it does not exist in the dictionary aswell. Thus, I get an error in the code, because the .PartId fails to be initialized. This is because in that textfile sometimes I have that value sometimes I do not.
After I have analized carefully I have noticed that the error happens in the Property statement, at Set(value As String) to be more exactly.
Public Property PartId() As String
Get
Return m_PartId
End Get
'here the error happens
Set(value As String)
m_PartId = value
End Set
End Property
Is there a way to avoid this in the Set statement? For example when there is an error then return an empty string?
Please let me know if there is something you do not understand.
Ok. Try Below. It works for me.
Dim partName As String
partName = "T0962"
parts.Add(New Intialization() With {
.PartName = partName,
.PartId = T.FirstOrDefault(Function(f) f.Key = partName).Value
})

Get specific value from .txt file using identifier VB.Net

I try to create a config file using .txt files, here I find it difficult to read the contents of the format.. already from yesterday I searched on google , but no similar case like me or maybe I missed it..
contents of .txt I have is as follows :
Cek Server IP = 192.168.10.1
Server IP = 192.168.10.1
Cek My Website = www.google.com
My Website = www.anothersite.com
this is my code :
WebControl.Source = New Uri("about:blank")
If My.Computer.Network.Ping("XXX") Then
WebControl.Source = New Uri("ZZZ")
Else
MsgBox("CANNOT CONNECT TO SERVER")
Exit Sub
End If
what i want is how to get value "192.168.10.1" From "Cek Server IP" then send to "XXX" and Get Value "192.168.10.1" from "Server IP" then send to "ZZZ"
How can i do that?
Sory for my bad english. Thanks.
As per my understanding, you want to read the values from your .txt file by giving its key. For that, you will have to write a function first that gets a key as a parameter and return the value:
private String GetValue(String key)
{
Boolean isValueFound = false;
String line = null;
//Open your file
using (StreamReader sr = new StreamReader("YourFile.txt"))
{
//Read it line-by-line
while ((line = sr.ReadLine()) != null)
{
//When the required line is found, set the flag and come out of the loop
if (line.Trim().StartsWith(key))
{
isValueFound = true;
break;
}
}
}
if (isValueFound)
{
//Split the line by using = as separator. So at index 0, you have the key and at index 1 you have the value
String[] strArray = line.Split('=');
//Trim the value before returning to get rid of extra spaces
return strArray[1].Trim();
}
else
{
//if value is not found, return null
return null;
}
}
Now you can call the above function like this:
//This line will give you 192.168.10.1
String result = this.GetValue("Cek Server IP");
//This line will return www.google.com
result = this.GetValue("Cek My Website");
For file I/O, the System.IO.File class has some useful methods, and for text files, the ReadLines method is probably what you want. You can then use String.Contains to check for the = character, and String.Split to separate the lines into key and value parts.
You could wrap this up into a class to read and parse your configuration file, and give you access to the specific values, e.g. (you will probably need some Imports and Option Infer On):
Public Class SettingsFile
Private ReadOnly _settings As IDictionary(Of String, String)
Private Sub New(settings As IDictionary(Of String, String))
_settings = settings
End Sub
Public Default ReadOnly Property Item(name As String) As String
Get
Dim value As String = Nothing
_settings.TryGetValue(name, value)
Return value
End Get
End Property
Public Shared Function Load(fileName As String) As SettingsFile
Dim settings = New Dictionary(Of String, String)()
For Each line In File.ReadLines(fileName).Where(Function(x) x.Contains("="))
Dim parts = line.Split("="c)
If parts.Count = 2 Then
settings(parts(0).Trim()) = parts(1).Trim()
End If
Next
Return New SettingsFile(settings)
End Function
End Class
You could then use this class in your code, e.g.:
Dim s = SettingsFile.Load("C:\Path\To\Settings.txt")
Dim s1 = s("Cek Server IP") ' 192.168.10.1
Dim s2 = s("Cek My Website") ' www.google.com
Dim s3 = s("Bad Key") ' Nothing

Declaring constant in VBA from a INI file

I have some const in a VBA module but I would like to put them in a INI file because I have other applications that use the same constants. This works:
Public Const PATH_DB As String = "\\server\folder\bdd.mdb"
This however doesn't work:
Public Const PATH_DB As String = getFromIni("path","db","C:\config.ini")
Public Function getFromIni(ByVal strSectionName As String, ByVal strEntry As String, ByVal strIniPath As String) As String
Dim x As Long
Dim sSection As String, sEntry As String, sDefault As String
Dim sRetBuf As String, iLenBuf As Integer, sFileName As String
Dim sValue As String
sSection = strSectionName
sEntry = strEntry
sDefault = ""
sRetBuf = Strings.String$(256, 0) '256 null characters
iLenBuf = Len(sRetBuf$)
sFileName = strIniPath
x = GetPrivateProfileString(sSection, sEntry, "", sRetBuf, iLenBuf, sFileName)
sValue = Strings.Trim(Strings.Left$(sRetBuf, x))
If sValue <> "" Then
getFromIni = sValue
Else
getFromIni = vbNullChar
End If
End Function
# C:\config.ini
[path]
db=\\server\folder\bdd.mdb
My getFromIni function actually works pretty well but not when I want to declare constants (it doesn't compile at all). I tried a global variable instead but for some reason, it doesn't work either, the variable cannot be found when used from another form in the same project (it only works when it's declared as a const, but I can't declare it as a const when getting the value from a function).
What's wrong?
You cannot assign a function call as the value of a CONST string. I would expect you to receive the error "Constant expression required" when running this.
Change
Public Const PATH_DB As String = getFromIni("path","db","C:\config.ini")
to
Public PATH_DB As String
Place the following call that gets the value from INI file in a initialize method (say Database Open event)
PATH_DB = getFromIni("path","db","C:\config.ini")

command to write symbol as text (Resharper? VS2010?)

I was watching a screencast of someone using Resharper (on VS 2010 or 2008, not sure) where they were able to fill in a test name with a string literal:
public class FooTest
{
public void "runs backgrounnd process until complete"
and then some command transformed it to
public class FooTest
{
public void runs_backgrounnd_process_until_complete()
{
I was wondering if anyone knew what that command was.
It is a visual studio macro that originally came from JP Boodhoo's Nothing But .NET Boot Camp class. This is it:
Sub ConvertLine()
If DTE.ActiveDocument Is Nothing Then Return
Dim isOpen As Boolean = OpenUndo("ConvertLine")
Dim selection As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
selection.SelectLine()
If selection.Text = "" Then Return
Dim classKeyword As String = "class """
Dim methodKeyword As String = "void """
Dim classIndex As Integer = selection.Text.IndexOf(classKeyword)
Dim methodIndex As Integer = selection.Text.IndexOf(methodKeyword)
If classIndex + methodIndex < 0 Then Return
Dim index = CType(IIf(classIndex >= 0, classIndex, methodIndex), Integer)
Dim prefix = selection.Text.Substring(0, index) + CType(IIf(classIndex >= 0, classKeyword, methodKeyword), String)
Dim description As String = selection.Text.Replace(prefix, String.Empty)
Dim conversion As String = Common.ReplaceSpacesWithUnderscores(description)
conversion = Common.ReplaceApostrophesWithUnderscores(conversion)
conversion = Common.ReplaceQuotesWithUnderscores(conversion)
selection.Text = prefix.Replace("""", String.Empty) + conversion
If prefix.Contains(methodKeyword) Then selection.LineDown() Else selection.LineUp()
selection.EndOfLine()
CloseUndo(isOpen)
End Sub
Looks like a "live template". If you notice, he types in fact, which is then replaced by the test method's skeleton. Edit, looks like it comes from the xUnit.net contrib project. You should be able to do something similar for an nUnit test case as well.