Solved

Form.shown Event speed

Posted on 2014-11-10
11
99 Views
Last Modified: 2014-12-04
Hi,

I've moved all my code from my startup form form_load event to the form_shown event because I was having problem with crystal reports in other forms giving me a  "crystal report print Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Every time I was printing or exporting a report

This has fixed the crystal reports issues I was having, the only thing is that now the startup form seems take more time to load, it seems to start "stuck" and then loads everything.

Though personally I don't mind the delay, some users might and I was wondering if there was a way to speed it up a little being that it is in the form_shown event?

Thank you,
0
Comment
Question by:FCapo
  • 5
  • 5
11 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 40433845
Are you rendering the report when the form is loaded?

mlmcc
0
 
LVL 18

Expert Comment

by:vasto
ID: 40433872
You should create a separate thread and load the report there. This will not slow the form
0
 

Author Comment

by:FCapo
ID: 40435138
Hi, the following code is in the form_shown event, I have no reports on this form, this is simply my start up form, the reports are located in other forms in my app;

I have no idea why but if I keep the following code in the form_load event it crashes my application when I try to open the forms that do have reports with "crystal report print Attempted to read or write protected memory. This is often an indication that other memory is corrupt." :

having it in the Form1_Shown event seems to solve the crash but it creates a delay when the start up form is first shown

Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        clientData = New Clients
        cliDataSet = clientData.getCliDataSet
        cliBindingSource = New BindingSource

        clientDataExtra = New clientsExtra
        clidatasetExtra = clientDataExtra.getCliDataSet
        cliBindingSourceExtra = New BindingSource

        rectAccessData = New ClientsAccess
        recAccDataSet = rectAccessData.getRecDataSet
        AccessBindingsource = New BindingSource

        clientAccessData = New ClientsAccess
        cliAccDataSet = clientAccessData.getrelateddata
        cliAccessBindingsource = New BindingSource

        timeData = New timesheet
        timeDataSet = timeData.getTimesheetHoursDataSet
        timeBindingSource = New BindingSource

        timeData1 = New timesheet
        timeDataSet1 = timeData1.getTimesheetHoursDataSet2
        timeBindingSource1 = New BindingSource

        budgetData = New ClientsAccess
        budgetdataset = budgetData.getBudget
        budgetBindingsource = New BindingSource

        With cliAccessBindingsource
            .DataSource = cliAccDataSet
            .DataMember = "projets"
        End With

        With budgetBindingsource
            .DataSource = budgetdataset
            .DataMember = "budget"
        End With

        With timeBindingSource
            .DataSource = timeDataSet
            .DataMember = "FeuillesDeTemps"
            .Sort = "ID"
        End With

        With timeBindingSource1
            .DataSource = timeDataSet1
            .DataMember = "FeuillesDeTemps"
            .Sort = "ID"
        End With

        With AccessBindingsource
            .DataSource = recAccDataSet
            .DataMember = "recevable"
        End With

        With cliBindingSource
            .DataSource = cliDataSet
            .DataMember = "DataTable"
            .Sort = "sName"
        End With

        With cliBindingSourceExtra
            .DataSource = clidatasetExtra
            .DataMember = "DataTable1"
        End With

        With cliCbx
            .DataSource = cliBindingSource
            .DataBindings.Add("text", cliBindingSource, "sName", False, DataSourceUpdateMode.Never)
            .DisplayMember = "sName"
        End With

        With extraCbx
            .DataSource = cliBindingSourceExtra
            .DataBindings.Add("text", cliBindingSourceExtra, "lCusId", False, DataSourceUpdateMode.Never)
            .DisplayMember = "lCusId"
        End With

        DataGridView1.DataSource = cliBindingSource

        For i = 0 To DataGridView1.Columns.Count - 1
            If i = 1 Then
            Else
                DataGridView1.Columns(i).Visible = False
            End If
        Next

        DataGridView1.Columns(1).HeaderText = "Nom du client"
        DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

        SimpleId.DataBindings.Add("text", cliBindingSource, "lId")
        cliSimplyExtra.DataBindings.Add("text", cliBindingSourceExtra, "lCusId")

        cliRue1.DataBindings.Add("text", cliBindingSource, "sStreet1")
        cliRue2.DataBindings.Add("text", cliBindingSource, "sStreet2")
        cliVille.DataBindings.Add("text", cliBindingSource, "sCity")
        cliPrv.DataBindings.Add("text", cliBindingSource, "sProvState")
        cliCode.DataBindings.Add("text", cliBindingSource, "sPostalZip")
        cliCourriel.DataBindings.Add("text", cliBindingSource, "sEmail")
        CliTxt.DataBindings.Add("text", cliBindingSource, "sCntcName")
        cliTelBur.DataBindings.Add("text", cliBindingSource, "sPhone1")
        cliTelCell.DataBindings.Add("text", cliBindingSource, "sPhone2")
        cliFax.DataBindings.Add("text", cliBindingSource, "sFax")
        cliTelDom.DataBindings.Add("text", cliBindingSourceExtra, "sUsrDfnd1")

        TextBox1.Select()

        If My.Settings.recevReminders = "yes" Then
            checkpopupsettings()
        End If

        If My.Settings.timesheetReminders = "yes" Then
            My.Settings.timesheetId = timeDataSet.FeuillesDeTemps.Compute("max(ID)", "")
            startEmailTimer()
            checktimersheetTimer()
        End If

        TabControl1.SelectedIndex = 1
        TabControl1.SelectedIndex = 0

    End Sub

Open in new window

0
 

Author Comment

by:FCapo
ID: 40437831
Any ideas?

Why does having my code in the startup Form1_Shown instead of Form1_load event impact crystal reports being able to print or export in another form?
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 40437860
I have no idea.

Most likely it is because of when the event fires in relation to when the report loads

mlmcc
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:FCapo
ID: 40438769
After looking further,

I've come to the conclusion that it has to do with the Access format of my database, which is .ACCDB

I've tried converting it to the standard .MDB version and updating it in my datasets, afterwards crystal report was no longer giving me this error when printing or exporting;

I've attached a screenshot of how Crystal Reports is set to connect to my database, when switching over from Provider=Microsoft.ACE.OLEDB.12.0  to Provider=Microsoft.Jet.OLEDB.4.0 it seemed to no longer give me this error.

I rather keep the .ACCDB since I have a few apps connecting to it, hopefully you can look at the screencapture and there may be a different way to connect to it that wouldn't provoke this error?

Thank you
screen.png
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40439114
What version of Crystal?

DId you download the Office database connectors?

mlmcc
0
 

Author Comment

by:FCapo
ID: 40440130
I have the full crystal report version 11.5.0.313 running with visual studio 2010 and the crystal reports Support Pack 12 (v.13.0.12.1494).

Yes I believe I have the right Office database connectors, I only get these issues when crystal reports sees more than one connection is made to the .ACCDB database, using the JET connection crystal reports doesn't give me any issues...
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 500 total points
ID: 40440606
CR XI R2 (v11.5.x.xxx) was built for .Net 2.0.  Are you running in a later .Net framework?

You probably want to change the reports to use the .Net version

mlmcc
0
 

Author Comment

by:FCapo
ID: 40440921
I'm running .net framework 4, How can I about changing the report to use the .Net version? Is there a setting I can change somewhere?

Thank you
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 500 total points
ID: 40441463
You should be able to install the CR for .Net then import the report into the application and save it.

mlmcc
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now