VB.NET Report Viewer Issue - sql-server

So I have a report server in a local area network that I want to access via a winform application with a Report viewer
my Report viewer control Name is rpt_ReportViewer
and here's the Code to view reports on the reportviewer rpt_ReportViewer
Private Sub rpt_GenerateReportBtn_Click(sender As Object, e As EventArgs) Handles rpt_GenerateReportBtn.Click
With rpt_ReportViewer
.ServerReport.ReportServerUrl = New Uri("http://SERVER/ReportServer")
.ServerReport.ReportPath = "/Search Assets Table/Search Assets Table"
.RefreshReport()
End With
End Sub
whenever I run this code it generates an exception in the report viewer saying "The Request Failed with HTTP Status 401: Unauthorized."
I don't know whats wrong but I used this very same code on a localhost and it worked http://localhost/reportserver
can anyone help me figuring out whats wrong please ? thanks in advance.

There's the solution
Dim Credential As New NetworkCredential("User name", "Password") 'Was missing this Line
With rpt_ReportViewer
.ServerReport.ReportServerCredentials.NetworkCredentials = Credential 'Was missing this line too
.ServerReport.ReportServerUrl = New Uri("http://SERVER/ReportServer")
.ServerReport.ReportPath = rpt_ReportsListBox.SelectedValue
.RefreshReport()
End With

Related

WebView2 on remote computer

I have a problem with webview2. I have WPF/vb.net app
First I can't make auto log in to the page.
Second, I tested it on remote computer and it doesn't work. It doesn't give errors, just empty field.
I appreciate any help
p.s.WebView2 Runtime is installed on both computers
front:
<wv2:WebView2 Name="webView2 " Source="pageName" CoreWebView2InitializationCompleted="zzz_CoreWebView2InitializationCompleted">
</wv2:WebView2>
back:
webView2 .EnsureCoreWebView2Async()
Private Sub webView2 _CoreWebView2InitializationCompleted(sender As Object, e As Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs)
Dim userName ="user"
Dim password = "password" webView2.CoreWebView2.ExecuteScriptAsync("document.getElementById(""signin_username"").InnerText='" & userName & "';")
p.s. for front I just deleted source and at the back I didn't wrote here the code for password and button, I think I will manage to do it if you can help me with just username.

Using SQL Server Authentication to connect to SSRS from a WinForms Application

I'm busy testing SSRS to see if it's a viable alternative to our current reporting solution. I've set up SSRS on my local machine and have developed a working report using SQL Server Report Builder. Now what I'm trying to do is to call the report from within a WinForms application and display it in a ReportViewer control. The problem is that I've set up SQL Server to use SQL Server Authentication and I'm struggling to figure out how to connect to it programmatically.
The code I've pieced together so far looks like this:
Imports Microsoft.Reporting.WinForms
Public Class frmMain
Public v_report_name As String = "TestReport"
Public v_report_server As String = "http://elnah-ict-dt006:80"
Public v_report_path As String = "/reports_SSRS/"
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'create parameter array
Dim paramlist As New List(Of Microsoft.Reporting.WinForms.ReportParameter)
'create a specific parameter required by the report
Dim param1 As New Microsoft.Reporting.WinForms.ReportParameter("ClientID")
'add values to the parameter here we use a variable that holds the parameter value
param1.Values.Add("0279")
'add parameter to array
paramlist.Add(param1)
'Set the processing mode for the ReportViewer to Remote
ReportViewer1.ProcessingMode = ProcessingMode.Remote
'use the serverreport property of the report viewer to select a report from a remote SSRS server
ReportViewer1.ServerReport.ReportServerUrl = New System.Uri(v_report_server)
ReportViewer1.ServerReport.ReportPath = v_report_path & v_report_name
'select where the report should be generated with the report viewer control or on the report server using the SSRS service.
'Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
'add the parameterlist to the viewer
ReportViewer1.ServerReport.SetParameters(paramlist)
Me.ReportViewer1.RefreshReport()
End Sub
End Class
When it hits the SetParameters line towards the bottom, it gets the following error message:
Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.MissingEndpointException
HResult=0x80131500
Message=The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.
Source=Microsoft.ReportViewer.WinForms
I've tried to find examples of how to set the username and password but from what I can tell, most examples are focused on using Windows Authentication. I've tried the following line but it doesn't work:
ReportViewer1.ServerReport.ReportServerCredentials = New ReportServerCredentials("SA", "mypassword")
I haven't worked in VB.NET for ages so please excuse any obvious errors.
Here's some code from a Web Forms project I was part of the team for recently:
private void SetCredentials()
{
var userName = ConfigurationManager.AppSettings["SSRSUserName"];
var passwordEncrypted = ConfigurationManager.AppSettings["SSRSUserPasswordEncrypted"];
var passwordPlainText = SI.Crypto3.Crypto.Decrypt(passwordEncrypted, PASSPHRASE);
var domain = ConfigurationManager.AppSettings["SSRSUserDomain"];
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passwordPlainText) && !string.IsNullOrEmpty(domain))
{
this.EventsHubReportViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials(userName, passwordPlainText, domain);
}
}
That's C# but hopefully you can see that the important part is that last line. I think that the equivalent in your case should be:
ReportViewer1.ServerReport.ReportServerCredentials = New ReportServerCredentials(userName, password, domain)
The domain value can be an empty String if your on the same domain as the server.
EDIT:
I looked more closely and the ReportServerCredentials class that code is using is one of our own. In your case, you can use the Microsoft.ReportViewer.WinForms.ReportServerCredentials class, which I don't think has a constructor like that. Looking at the documentation for the NetworkCredentials property of that type indicates that you need to do this:
Dim credentials As New NetworkCredential(userName, password, domain)
ReportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credentials

Error in File Temp__.rpt

I made reports using database name Test. SQL Server as backend.
Used DSN. Even configured in ODBC DataSource.
Now I changed my report to mainDb
Some reports worked fine. Others throw error when database name changed.
Error message shown below.
Any solution for this?
I searched on internet, found similar errors based on invalid login or some implementation error. I don't know what exactly my error means.
My small code is posted here.
Private Sub DisplayReport()
Try
Dim report As New Summary
Dim pubdbname as String = "mainDb" '-------This name is correct.'
With report
.DataSourceConnections.Item(0).SetConnection("bonny", Pubdbname, True)
.SetParameterValue("#CompYear", PubYear1)
.SetParameterValue("#CompNo", mComp1)
.SetParameterValue("#accode", PubAcCode)
.SetParameterValue("#Trtype", PubTrTp)
.SetParameterValue("#SBkCd", PubSBkCd)
.SummaryInfo.ReportTitle = "Summary Report" & "_" & Format(CDate(FromDate.Text), "ddMMyyyy") & "-" & Format(CDate(ToDate.Text), "ddMMyyyy")
CReports.CRViewer.ReportSource = report
CReports.Show()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thank You.

How to configure NBug to send email

I have a WPF application that I would like to configure to use NBug to send error reports via email.
The config tool works correctly, and I receive a test email, but when adding NBug to the application and triggering an uncaught exception, I do not receive an email. The only configuration I have done matches the Getting Started guide (loosely translated to VB.Net).
Private Sub Application_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
AddHandler AppDomain.CurrentDomain.UnhandledException, NBug.Handler.UnhandledException
AddHandler Application.Current.DispatcherUnhandledException, NBug.Handler.DispatcherUnhandledException
AddHandler TaskScheduler.UnobservedTaskException, NBug.Handler.UnobservedTaskException
NBug.Settings.UIMode = NBug.Enums.UIMode.Full
NBug.Settings.StoragePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
NBug.Settings.AddDestinationFromConnectionString("Type=Mail;From=bugs#xxx.com;Port=465;SmtpServer=smtp.gmail.com;To=support#xxx.com;UseAttachment=True;UseAuthentication=True;UseSsl=True;Username=bugs#xxx.com;Password=xxx;")
NBug.Settings.ReleaseMode = True
End Sub
The above code has removed username/password from our gmail account that is used for bug reports.
Any ideas what is wrong with the config or how I could debug?
The zip file attachment is being generated, but no email is sent.
Simply use NBug.Settings.ReleaseMode = true; as described in this intro post: http://www.soygul.com/nbug/

Getting RavenDB Client API to work in Silverlight

I just learned that RavenHQ is an easy-to-use database for .NET and especially Silverlight. I'm trying to insert some Test Data (see Code) but it won’t work. I think I am missing something big because I'm new to RavenDB.
I added the references to the project and created clientaccesspolicy.xml and crossdomain.xml. I get (Firebug) an HTTP 200 Response to "GET clientaccesspolicy.xml" from 1.ravenhq.com but nothing else happens and no data is inserted. Any Ideas would be much appreciated.
Private Sub TestRavenDB()
Try
Dim ds = New DocumentStore()
ds.Url = "https://1.ravenhq.com/databases/AppHarbor_60e82bd1-234f-4178-a59a-b527a1d391bb"
ds.ApiKey = "1f827c44-3e38-4e66-8801-83ba03b01f67"
ds.Initialize()
Dim p As New Person("Donald")
Dim session As IAsyncDocumentSession = ds.OpenAsyncSession()
session.Store(p)
session.SaveChangesAsync()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Note that you have SaveChangesAsync there. Before your test return, you need to wait for that to complete.

Resources