Report viewer, Report is being generated runs forever! - reportviewer

Ok I have a reportviewer that has worked perfectly up untill now, now all of a sudden it never gets past the "Report is being generated" message. The code up untill the Report.RefreshReport() is exactly and works just fine, it creates a DataSource for the report, the report itself has also not changed.
Anybody ever had this problem before and know what might be wrong with it.
Thanks in advance for all who reply!
Code segment:
Dim myemployeedetails As String() = Split(Me.ToolStripComboBox2.SelectedText, ",")
Dim paramlist As New List(Of Microsoft.Reporting.WinForms.ReportParameter)
Dim param1 As New Microsoft.Reporting.WinForms.ReportParameter("StartDate", Startdate)
Dim param3 As New
Microsoft.Reporting.WinForms.ReportParameter("EmployeeParam", Trim(myemployeedetails(1)))
paramlist.Add(param1)
paramlist.Add(param3)
Me.ReportViewer1.LocalReport.SetParameters(paramlist)
Me.CompanyCollectionBindingSource.DataSource = CompanyCollection.GetCompanys(GroupID, Startdate)
Me.ReportViewer1.RefreshReport() 'Sticks here!

Try running the query that populates your report outside of the ReportViewer context ( say, in Management Studio ).
If your calling code hasn't changed and your report hasn't changed, your data ( and retrieval of said data ) should be high on your inspection list.

Turns out the domain for an image has been changed, so the report couldnt find the image. Didnt know this because the guy that sorts that out is snowed in. Sorted now, thankyou for your quick reply Paul.

Try to verify the postback in the Page_Load() event,
if (!IsPostBack)
{
CallReportHere() //I recommend a method for all the operations related with the ReportViewer control
}
Only refresh the report if !IsPostBack, the problem is related with setting the parameters values. This problem appears with the VS2010 and continues with VS2012, specially when you migrated your solution from VS2008.
That worked for me.

Related

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()

Crystal Report randomly breaks when setting parameter value

I have searched high and low for a fix to this, so I apologize in advance if this is a dumb question or a repeat question.
So I have this Crystal Report, no I unfortunately do not know the version I'm on, that works most of the time and randomly breaks under the exact same conditions as when it works. On the times that it breaks, when I go to set the parameter with ApplyCurrentValue, it immediately pops up a window that asks for all parameters (as if none were set). When I press exit, it breaks with
System.NullReferenceException: Object reference not set to an instance
of an object. at
CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.ApplyCurrentValues(ParameterValues
currentValues)
Below is the code. Also, every parameter I pass is the correct value so none of them are null and actually have a value.
rpt.SetDataSource(ds)
crv.ReportSource = rpt
AddCrystalReportParameters("EntityName", entityName)
AddCrystalReportParameters("dtFrom", datFrom.ToShortDateString())
AddCrystalReportParameters("dtTo", datTo.ToShortDateString())
AddCrystalReportParameters("RectEntityDesc", rectEntityDesc)
Here is the method that I use.
Sub AddCrystalReportParameters(ByVal sFieldName As String, ByVal sValue As String)
Dim discreteValue As New ParameterDiscreteValue()
Dim values As New ParameterValues()
values = rpt.DataDefinition.ParameterFields(sFieldName).CurrentValues()
discreteValue.Value = sValue 'Assign parameter
values.Add(discreteValue)
rpt.DataDefinition.ParameterFields(sFieldName).ApplyCurrentValues(values)
End Sub
Because it is so random for when it breaks, it has made testing it extremely difficult. I was thinking that maybe the report isn't loaded, but I checked for rpt.IsLoaded in which it said it was even though it went on to break when it went to add the parameter.
Thanks for your help!
You do not need to set parameters if you are setting the datasource using SetDataSource
First Create Parameters in the report itself with names (EntityName,dtFrom,dtTo and RectEntityDesc) as you described. then add these parameters to your report as objects then in the code you can set the values as code below:
rpt.SetParameterValue("#EntityName", EntityName)
rpt.SetParameterValue("#dtFrom", dtFrom.SelectedDate)
rpt.SetParameterValue("#dtTo", dtTo.SelectedDate)
rpt.SetParameterValue("#RectEntityDesc", rectEntityDesc)
this code used because you have already added the parameters to the report you are only setting the value of each parameter.

ComboBox Unreadable in Multithreaded

I'm trying to build a small application that connects to a couple databases to move data from one to the other, manipulating and verifying data is it moves. I had everything working, but wanted to add the majority of the work to a second thread so that the initial window is still functional.
I have most of it working fine so far, except for one pesky bit. I allow the user to choose the database from a list of databases on a MSSQL Server. Without the threading, the program can read the text of the combo box without issue. As soon as I add in threading, it can't read the text of the combo box. It doesn't have issues reading the text boxes that contain the servername/username/password, just with this one combo box. The code below is in a class that handles all my database functions. The combobox is on the main form (frmMain) that is launched when you run the application. frmMain is the default form for the application.
Without threading I was doing this.
Me._sqlDB = New sqlDatabase
Me._sqlDB.DBServer = frmMain.txtServer.Text
Me._sqlDB.DBUsername = frmMain.txtUser.Text
Me._sqlDB.DBPassword = frmMain.txtPassword.Text
Me._sqlDB.DBDatabase = frmMain.cboSQLDatabase.Text
When I added the thread, it couldn't read from the combo box (along with a host of other issues due to non-threadsafe calls). I did some research and added in some delegates and invokes. This solved the rest of the issues I was running into, but the combobox was still unreadable.
I created a function with a delegate to read the combobox, hoping that it was a thread related issue, but still no luck. The database connection setup code is in the database class I mentioned above and the GetDatabaseName function is in the main form (frmMain).
'Database Connection Setup
Me._sqlDB = New sqlDatabase
Me._sqlDB.DBServer = frmMain.txtServer.Text
Me._sqlDB.DBUsername = frmMain.txtUser.Text
Me._sqlDB.DBPassword = frmMain.txtPassword.Text
Me._sqlDB.DBDatabase = frmMain.GetDatabaseName
'GetDatabaseName Function for Connection String Setup
Delegate Function GetDatabaseNameDel() As String
Public Function GetDatabaseName() As String
Dim DBName As String = ""
If Me.cboSQLDatabase.InvokeRequired Then
DBName = Me.Invoke(New GetDatabaseNameDel(AddressOf GetDatabaseName))
Else
DBName = Me.cboSQLDatabase.Text
End If
Return DBName
End Function
I have tried several of the combobox properties, including SelectedItem, SelectedText, and Text. None of them have any value when the GetDatabaseName function is called. In fact, when run in debug mode and pausing the code execution, Visual Studio shows that the combobox has nothing in it (Count = 0, Items collection is empty).
The combobox is populated using a SqlDataReader that reads the list of database names from the server.
I also tried changing the setup to use a BackgroundWorker, but I get the same results.
Any thoughts on why the combobox is appearing as empty when running as a separate thread?
With a little more research, I found a possible solution, but it seems really janky. If I change the call to the function to use this:
Me._sqlDB.DBDatabase = CType(My.Application.OpenForms.Item("frmMain"), frmMain).GetDatabaseName
It works, but this seems like a very odd workaround for the issue. Is there a better way to refer to the control on the active form?

How to set user "logon to" AD attribute in VB.NET

I'm working on upgrading a solution in VB.NET that is heavily based on Active Directory. As of now, I'm trying to add a PC restriction to a new AD User upon user creation. Essentially, I need to update the Logon To attribute to include 1 or more PCs, how do I go about doing this?
I learned that I am interested in the IADsUser property "LoginWorkstations" (thanks to http://msdn.microsoft.com/en-us/library/Aa746340). As of now, I have code that can fetch this attribute from any AD user, but I cannot set it.
Here is the code I have to fetch the attribute:
Dim userADObject As new DirectoryEntry(ADPath)
Dim logonToPC as String = userADObject.InvokeGet("LoginWorkstations")(0).ToString
That will fetch the first restricted PC (if there is one) and save it in logonToPC and will look something like "PC10000"
That works great, so intuitively I would assume something like this would work:
Dim userADObject As new DirectoryEntry(ADPath)
Dim args() As Object = {"PC100001"}
userADObject.InvokeSet("LoginWorkstations", args)
But it doesn't work... It just throws a rather unhelpful exception.
I've tried testing this approach with a different attribute and it works just fine. Not much out there on Google either unfortunately...
Any help would be greatly appreciated.
You should be able to do this fairly easily - also: note that you should use the userWorkstations LDAP attribute (see note here) - this is multi-valued, e.g. it allows multiple entries.
Dim userADObject As new DirectoryEntry(ADPath)
userADObject.Properties("userWorkstations").Add("PC001")
userADObject.Properties("userWorkstations").Add("PC002")
userADObject.Properties("userWorkstations").Add("PC003")
userADObject.CommitChanges()
If you have the necessary permissions to update Active Directory, that should basically do it, I think.
Found the solution that works. I took marc_s's code and modified a bit to work properly. here's what I have:
Dim userADObject As New DirectoryEntry(Me.ADPath)
'Grab the previous restriction, because we may have to clear it first in the future
Dim priorRestriction As String = userADObject.Properties("userWorkstations").Value
If priorRestriction = "" Then
'Simply add
userADObject.Properties("userWorkstations").Add("PC001,PC002")
Else
'Important - We have to clear the old restriction before adding the new
userADObject.Properties("userWorkstations").Remove(priorRestriction)
'Now add the new restriction
userADObject.Properties("userWorkstations").Add(priorRestriction & ",PC003")
End If
'Commit!
userADObject.CommitChanges()
Something that gave me some pretty good grief what that I you can't have a space in the string being added. Example: .Add("PC001, PC002") has to be .Add("PC001,PC002")

Autocomplete list does not show all possible completions with BindingSource.Item

I've got a BindingSource for a DataSet. I'm fairly new to this whole binding business and databases, and it took me hours to figure out how to use BindingSource to get to an item, because the Row method was not included in the autocomplete. Not to confuse anyone, here's some sample code:
Dim somePreperty As String
Dim dataSet As New MyDataSet
Dim table As New MyDataSetTableAdapters.MyTableAdapter
Dim source As New BindingSource
source.DataSource = dataSet
source.DataMember = "SomeMember"
table.Fill(dataSet.SomeMember)
lablCabinet.DataBindings.Add("Text", source(0), "MemberID") '<This works fine>'
someProperty = source.Item(0).Row("ProductModel") '<So does this>'
The code runs perfectly and does exactly what I want. My problem is the following: When I've typed in source.Item(0)., autocomplete does not display Row in the list. Is this perhaps not the best way to do what I'm doing? Is there a reason it's hidden? Is this a good coding practice to do so? The fact that is wasn't there took me lots of time Googling, so I'm trying to figure out whether it's a Visual Studio glitch or my own.
Thanks in advance! = )
source.item(0) returns an object, so intellisense has no idea what is is.
You know what it should be, the compiler does not.
If you cast it first to a table or assing it to a table, intellisense will kick in.
So either:
ctype(source.item(0),datatable)
Or
dim tbl as datatable=source.item(0).