الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

خطأ عند عرض التقارير Attempted to read or write protected memory. This is often an indication that other memory is corrupt

بدأه Ayman-Sy في 6 فبراير 2013 · 4 رد · 626 مشاهدة · في تصميم وبرمجة التقارير
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته , أعزائي الأعضاء

 

هذا الخطأ : Attempted to read or write protected memory. This is often an indication that other memory is corrupt

 

يظهر لي بعد عرض تقرير معين أكثر من مرة , وأحيانا مرة , وأحيانا ولا مرة !

 

طبعا أخذت بعين الإعتبار مشاكل الذاكرة مثل leak , أيضا أي Unmanaged Resources  أقوم بعمل Dispose()  لها بعد الإنتهاء منها حتى كل التقارير الموجودة أقوم بعمل Close() ثم Dispose() لها بعد الإنتهاء منها , ولكن بدون جدوى !

 

هذا هو كود نافذة التقارير :

 

Imports System.Drawing.Printing
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data.OleDb

Public Class rep
    Public isEm, isShown As Boolean
    Public repName As String
    Dim CurrentReport As CrystalDecisions.CrystalReports.Engine.ReportDocument
    Public onNumT As String
    Public cl As Boolean
    Function loadSource(ByVal placeType As String) As DataTable
        Dim Conn As New OleDbConnection(ConnectionString)
        Dim Command As New OleDbCommand
        Command.CommandType = CommandType.Text
        Select Case placeType
            Case "city"
                Command.CommandText = "select placeName as TT from places where placeType = 'مدينة' order by placeName"
            Case "port"
                Command.CommandText = "select placeType+' '+placeName as TT from places where placeType in('مطار','ميناء','حدود') order by placeName"
            Case "driver"
                Command.CommandText = "select driverName from drivers"
        End Select
        Command.Connection = Conn
        Dim dataadapter As New OleDb.OleDbDataAdapter(Command.CommandText, Conn)
        Try
            Dim dt As New DataTable
            dataadapter.Fill(dt)
            Return dt.Copy
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Exclamation)
        Finally
            dataadapter.Dispose()
            Conn.Dispose()
            Command.Dispose()
        End Try
    End Function
    Private Sub LogOn(ByVal poReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal strServer As String, ByVal strTable As String, ByVal strUsername As String, ByVal strPassword As String)
        Dim lsMethod As String = System.Reflection.MethodBase.GetCurrentMethod().Name
        Dim loConnInfo As New CrystalDecisions.Shared.ConnectionInfo
        loConnInfo.ServerName = strServer
        loConnInfo.DatabaseName = strTable
        loConnInfo.UserID = strUsername
        loConnInfo.Password = strPassword
        Dim loTables As CrystalDecisions.CrystalReports.Engine.Tables
        Dim loTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim loTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
        loTables = poReport.Database.Tables

        For Each loTable In loTables
            loTableLogonInfo = loTable.LogOnInfo
            loTableLogonInfo.ConnectionInfo.ServerName = strServer
            loTableLogonInfo.ConnectionInfo.ServerName = strTable
            loTable.ApplyLogOnInfo(loTableLogonInfo)

        Next
     
    End Sub
    Sub loadReport()
        Cursor = Cursors.WaitCursor
        Select Case repName
            Case "moves1"
                CurrentReport = New moves1
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                movesPanel.BringToFront()
                CityMoves.DataSource = loadSource("city")
                CityMoves.ValueMember = "TT"
                Me.AcceptButton = showButtonMoves
                movTypeMoves.SelectedItem = "الكل"
            Case "moves2"
                CurrentReport = New moves2
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                movesPanel.BringToFront()
                CityMoves.DataSource = loadSource("city")
                CityMoves.ValueMember = "TT"
                Me.AcceptButton = showButtonMoves
                movTypeMoves.SelectedItem = "الكل"
            Case "arrTrip"
                CurrentReport = New arrivalReport
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                tripsPanel.BringToFront()
                portTrip.DataSource = loadSource("port")
                portTrip.ValueMember = "TT"
                tripCaption.Text = "تاريخ الوصول"
                Me.AcceptButton = showButtonTrip
            Case "leaTrip"
                CurrentReport = New leavingReport
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                tripsPanel.BringToFront()
                portTrip.DataSource = loadSource("port")
                portTrip.ValueMember = "TT"
                tripCaption.Text = "تاريخ المغادرة"
                Me.AcceptButton = showButtonTrip
            Case "transReports"
                CurrentReport = New transReports
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                Me.AcceptButton = trButton
                transportPanel.BringToFront()
            Case "MovesPayes"
                CurrentReport = New MovesPayes
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                EmptyMovesPanel.BringToFront()
                driverName.DataSource = loadSource("driver")
                driverName.ValueMember = "driverName"
                Me.AcceptButton = showButtonEmptymoves
            Case "MonthlyMovesPayes"
                CurrentReport = New MonthlyMovesPayes
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                EmptyMovesPanel.BringToFront()
                driverName.Visible = False
                drCaption.Visible = False
                Me.AcceptButton = showButtonEmptymoves
            Case "trShow"
                CurrentReport = New transReports
                LogOn(CurrentReport, DataBasePath, DataBasePath, "Admin", "")
                Me.AcceptButton = trButton
                hp.BringToFront()
                Me.AcceptButton = Nothing
                CurrentReport.SetParameterValue(0, onNumT)
                Report.ReportSource = CurrentReport
        End Select
        Cursor = Cursors.Default
    End Sub
    Private Sub rep_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Tag = Me.Text
        loadReport()
        If cl = True Then Close()
    End Sub
    Private Sub rep_Shown(sender As System.Object, e As System.EventArgs) Handles MyBase.Shown
        Cursor = Cursors.Default
        isShown = True
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles printt.Click
        Dim m As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim oo As New PrintDialog
        Try
            If Report.ReportSource Is Nothing Then Exit Sub Else m = Report.ReportSource
            oo.AllowSomePages = True
            If oo.ShowDialog() <> DialogResult.OK Then Exit Sub
            m.PrintToPrinter(oo.PrinterSettings, oo.PrinterSettings.DefaultPageSettings, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight)
        Finally
            m.Dispose()
            oo.Dispose()
        End Try
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles send.Click
        If Report.ReportSource Is Nothing Then Exit Sub
        Dim mailf As New MailForm
        Dim reportt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Try
            Cursor = Cursors.WaitCursor
            reportt = CurrentReport
            FileIO.FileSystem.CreateDirectory(Application.StartupPath & "\temp\")
            reportt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Application.StartupPath & "\temp\temp.pdf")
            If FileIO.FileSystem.FileExists(Application.StartupPath & "\temp\temp.pdf") = True Then mailf.addfile(Application.StartupPath & "\temp\temp.pdf") Else Exit Sub
            mailf.bodyy.Text = " "
            mailf.subject.Text = "شركة البركة"
            mailf.ShowDialog()
            Cursor = Cursors.Default
            Kill(Application.StartupPath & "\temp\temp.pdf")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight)
        Finally
            reportt.Close()
            reportt.Dispose()
            mailf.Dispose()
        End Try
    End Sub
    Private Sub rep_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Cursor = Cursors.Default
        
    End Sub

    Private Sub showButtonMoves_Click(sender As System.Object, e As System.EventArgs) Handles showButtonMoves.Click, showButtonEmptymoves.Click, showButtonTrip.Click, CityMoves.SelectedValueChanged, dateMoves.ValueChanged, DateTrip.ValueChanged, driverName.SelectedValueChanged, DriverDate.ValueChanged, dateMoves.ValueChanged, portTrip.SelectedValueChanged, trButton.Click, movTypeMoves.SelectedValueChanged
        Try
            If isShown = False Then Exit Sub
            If CurrentReport Is Nothing Then loadReport()
            Report.ReportSource = Nothing
            Select Case repName
                Case "moves1", "moves2"
                    CurrentReport.SetParameterValue("d1", dateMoves.Value)
                    CurrentReport.SetParameterValue("cit", CityMoves.GetItemText(CityMoves.SelectedItem).Replace("المدينة المنورة", "المدينة"))
                    CurrentReport.SetParameterValue("moveType", movTypeMoves.Text)
                    Report.ReportSource = CurrentReport
                Case "leaTrip", "arrTrip"
                    CurrentReport.SetParameterValue("d1", DateTrip.Value.ToShortDateString)
                    CurrentReport.SetParameterValue("customport", portTrip.GetItemText(portTrip.SelectedValue))
                    Report.ReportSource = CurrentReport
                Case "MovesPayes"
                    CurrentReport.SetParameterValue("drivername", driverName.GetItemText(driverName.SelectedValue))
                    CurrentReport.SetParameterValue("mont", DriverDate.Value.Month)
                    Report.ReportSource = CurrentReport
                Case "MonthlyMovesPayes"
                    CurrentReport.SetParameterValue("mont", DriverDate.Value.Month)
                    Report.ReportSource = CurrentReport
                Case "transReports"
                    CurrentReport.SetParameterValue(0, onNum.Text)
                    Report.ReportSource = CurrentReport
            End Select
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub nMoves1_Click(sender As System.Object, e As System.EventArgs) Handles nMoves1.Click

        Report.ShowNextPage()

    End Sub

    Private Sub nfMoves1_Click(sender As System.Object, e As System.EventArgs) Handles nfMoves1.Click
        Report.ShowLastPage()
    End Sub

    Private Sub pMoves1_Click(sender As System.Object, e As System.EventArgs) Handles pMoves1.Click
        Report.ShowPreviousPage()
    End Sub

    Private Sub pfMoves1_Click(sender As System.Object, e As System.EventArgs) Handles pfMoves1.Click
        Report.ShowFirstPage()
    End Sub

    Private Sub rep_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Report.ReportSource = Nothing
        CurrentReport.Close()
    End Sub

    

End Class

 

ملاحظة : repname متغير عام أقوم عن طريقه بتحديد التقرير المراد عرضه في النافذة

 

شكرا لكم جميعا :)

تم تعديل هذه المشاركة بواسطة Ayman-Sy في 6 فبراير 2013 في 22:56

#2

قبل الرد علي مشكلتك حجم الكود كبير جدا وان اعتقد 10 من هذا الكود كافي

ماذا لو عندك 100 تقرير تكتب كود كام سطر قد يعطيك هذا الكود فكره افضل

 protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            ReportDocument crRep = new ReportDocument();
            crRep.Load(Session["ReportPath"].ToString());

            if (Session["RecordSelectionFormula"].ToString() != "0")
                crRep.RecordSelectionFormula = Session["RecordSelectionFormula"].ToString();

            SqlConnectionStringBuilder csbDb = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
            Tables crTables;
            TableLogOnInfo crTableLogOnInfo;
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            crConnectionInfo.ServerName = csbDb.DataSource.ToString();
            crConnectionInfo.DatabaseName = csbDb.InitialCatalog.ToString();
            crConnectionInfo.UserID = csbDb.UserID.ToString();
            crConnectionInfo.Password = csbDb.Password.ToString();
            crTables = crRep.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                string x = crTable.Name;
                crTableLogOnInfo = crTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogOnInfo);
            }

            crRep.SetParameterValue("@MSSDirectorateID", Session["ddlGov"].ToString());
            crRep.SetParameterValue("@MSSDepartmentID", Session["ddlDept"].ToString());
            crRep.SetParameterValue("@MSSStationID", Session["ddlUnit"].ToString());

            if (Session["ddlYear"].ToString() !="1901")
                crRep.SetParameterValue("@nYear", Session["ddlYear"].ToString());

            crRep.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "export");

            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "text/richtext";
            Response.Flush();
            Response.Close();

            crRep.Close();
            crRep.Dispose();
        }
        catch (Exception EX) { 
            Label1.Text = EX.Message.ToString();
        }
    }

ما هو حجم البيانات

تم تعديل هذه المشاركة بواسطة KARIMSOFT في 8 فبراير 2013 في 23:53

1
#3

شكرا لك أخي الكريم على النصيحة , لكن المشكلة ليست في طول الكود :)

 

حجم البيانات لا يتجاوز في أقصى الحالات الـ 4 صفحات

تم تعديل هذه المشاركة بواسطة Ayman-Sy في 7 فبراير 2013 في 03:24

#4

للرفع

#5

ممكن ترفق المشروع

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…