تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] Reading from the stream has failed
#20
.....

بناء على طلبك باستخدام Reader
تم الاستغناء عن LIMIT وOFFSET
تم الاستغناء عن BackgroundWorker واستبدالها بـ Threading.Thread

جرب بنسخة مؤقتة من المشروع، وبدء المهمة يتم بالضغط على زر Button1
كود :
' جملة الاتصال مع قاعدة بيانات المصدر
Private connStrVB As String = " Server = localhost;  Port = 3306;  User id = root;  Password = 123;  Database = tempdb ; "

' جملة الاتصال مع قاعدة بيانات الهدف
Private connStrBB As String = " Server = localhost;  Port = 3306;  User id = root;  Password = 123;  Database = tempdb ; "


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' تعطيل فحص تضارب نداء المهمات
    Control.CheckForIllegalCrossThreadCalls = False

End Sub

' تعريف متغير مهمة بدون إنشاءها
Private thrd As Threading.Thread

' مجموع أسطر نتائج الاستعلام
Private rowsCount As Integer


' بدء العمل
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ' التأكد من أن المهمة ما زالت في قيد العمل
    If thrd IsNot Nothing Then
        If thrd.ThreadState = Threading.ThreadState.Running _
        Or thrd.ThreadState = Threading.ThreadState.Background Then
            MsgBox("عفواً... نرجو الانتظار، فما زالت المهمة في قيد العمل")
            Exit Sub
        End If
    End If

    ff("الان .. النظر في جدول المستخدمين")

    ' معرفة المجموع الإجمالي لأسطر النتائج المراد جلب بياناتها كامله
    Using conn As New MySqlConnection(connStrVB)

        conn.Open()
        rowsCount = New MySqlCommand(" SELECT COUNT(`userid`) FROM `user` ", conn).ExecuteScalar
        conn.Close()

        If rowsCount > 0 Then

            ff("تم إيجاد عدد المستخدمين ومجموعهم: " & rowsCount & vbNewLine)

            '' تحديد مجال شريط الانتظار
            'Me.ProgressBar1.Maximum = rowsCount

            ' إنشاء مهمة جديدة
            thrd = New Threading.Thread(AddressOf thrdTask)

            ' وضع المهمة في الخلفية
            thrd.IsBackground = True

            ' بدء المهمة
            thrd.Start()

        End If

    End Using

End Sub



' إجراء المهمة
Private Sub thrdTask()

    ff("تم البدء في عملية النسخ...")

    ' connVB إنشاء إتصال مع قاعدة البيانات لـ
    Using connVB As New MySqlConnection(connStrVB)

        ' connBB إنشاء إتصال مع قاعدة البيانات لـ
        Using connBB As New MySqlConnection(connStrBB)

            ' connBB فتح الإتصال مع الهدف
            connBB.Open()


            ' إنشاء أمر الإستعلام من الجدول المصدر
            Using commVB As New MySqlCommand(" SELECT * FROM `user` ORDER BY `userid` ", connVB)

                ' connVB فتح الإتصال مع المصدر
                connVB.Open()


                '------------------------------

                ' readerVB تنفيذ أمر القراءة من المصدر
                Dim readerVB As MySqlDataReader = commVB.ExecuteReader()


                '------------------------------
                ' أعتقد أن هذين السطرين يكونان قبل الحلقة أي خارجها
                Dim wc As New WebClient
                wc.Headers.Add("cookie", gco)
                '------------------------------


                ' حلقة القراءة في الوضع المتصل
                While readerVB.Read()


                    ' HtmlAgilityPack لم أتطرق لهذا الجزء لعدم استخدامي لـ ----------------------------------------
                    Dim theid As String = readerVB("userid")
                    Dim url As String = "http://127.0.0.1/" & gvbfolder & "/member.php?u=" & readerVB("userid")
                    Dim html As String = ""

                    '' تم نقل هذين السطرين قبل الحلقة
                    'Dim wc As New WebClient
                    'wc.Headers.Add("cookie", gco)

                    html = wc.DownloadString(url)

                    Dim hdoc As New HtmlAgilityPack.HtmlDocument
                    hdoc.LoadHtml(html)

                    Dim nod As HtmlAgilityPack.HtmlNode = hdoc.GetElementbyId("userinfo")
                    Dim u As New HtmlAgilityPack.HtmlDocument
                    u.LoadHtml(nod.InnerHtml)

                    Dim th As HtmlAgilityPack.HtmlNode = u.DocumentNode.SelectSingleNode("//span[@class='member_username']")
                    Dim th2 As HtmlAgilityPack.HtmlNode = u.DocumentNode.SelectSingleNode("//span[@class='usertitle']")

                    Dim about As HtmlAgilityPack.HtmlNode = hdoc.GetElementbyId("view-aboutme")

                    Dim h As New HtmlAgilityPack.HtmlDocument
                    h.LoadHtml(about.InnerHtml)

                    Dim toqee As HtmlAgilityPack.HtmlNode = h.DocumentNode.SelectSingleNode("//div//div")
                    '----------------------------------------------------------------------------------------------


                    ' تكوين جملة إسكويل للإضافة
                    Dim sqlBB As String = _
                        " INSERT INTO `mybb_users` " & _
                        "   ( `username`, `password`, `salt`, `email`, `postnum`, `threadnum`, `website`, `usertitle`, `usergroup`, `additionalgroups`, `signature`, `buddylist`, `ignorelist`, `pmfolders`, `notepad`, `usernotes` ) " & _
                        " VALUES " & _
                        "   ( @username , @password , @salt , @email , @postnum , @threadnum , @website , @usertitle , @usergroup , @additionalgroups , @signature , @buddylist , @ignorelist , @pmfolders , @notepad , @usernotes  ) "

                    ' إنشاء أمر الإضافة في الجدول الهدف
                    Using commBB As New MySqlCommand(sqlBB, connBB)

                        ff("________________________________________" & vbNewLine & "حفظ اسم المستخدم: " & th.InnerText.Trim & vbNewLine)

                        ' تمرير قيم البارامترات
                        commBB.Parameters.AddWithValue("@username", th.InnerText.Trim)
                        commBB.Parameters.AddWithValue("@password", readerVB("password"))
                        commBB.Parameters.AddWithValue("@salt", readerVB("salt"))
                        commBB.Parameters.AddWithValue("@email", readerVB("email"))
                        commBB.Parameters.AddWithValue("@postnum", "0")
                        commBB.Parameters.AddWithValue("@threadnum", "0")
                        commBB.Parameters.AddWithValue("@website", readerVB("homepage"))
                        commBB.Parameters.AddWithValue("@usertitle", th2.InnerText.Trim)

                        Select Case readerVB("usergroupid")
                            Case "1" : commBB.Parameters.AddWithValue("@usergroup", "1")
                            Case "2" : commBB.Parameters.AddWithValue("@usergroup", "2")
                            Case "3" : commBB.Parameters.AddWithValue("@usergroup", "5")
                            Case "4" : commBB.Parameters.AddWithValue("@usergroup", "5")
                            Case "5" : commBB.Parameters.AddWithValue("@usergroup", "3")
                            Case "6" : commBB.Parameters.AddWithValue("@usergroup", "4")
                            Case "7" : commBB.Parameters.AddWithValue("@usergroup", "6")
                            Case "8" : commBB.Parameters.AddWithValue("@usergroup", "7")
                        End Select

                        commBB.Parameters.AddWithValue("@additionalgroups", readerVB("membergroupids"))
                        commBB.Parameters.AddWithValue("@signature", toqee.InnerHtml)
                        commBB.Parameters.AddWithValue("@buddylist", "")
                        commBB.Parameters.AddWithValue("@ignorelist", "")
                        commBB.Parameters.AddWithValue("@pmfolders", "")
                        commBB.Parameters.AddWithValue("@notepad", "")
                        commBB.Parameters.AddWithValue("@usernotes", "")


                        ' تنفيذ أمر الإضافة
                        commBB.ExecuteNonQuery()

                        '' تقدم شريط الانتظار
                        'Me.ProgressBar1.Increment(1)

                    End Using 'commBB

                End While 'readerVB



                ' connVB إغلاق الاتصال المصدر
                connVB.Close()

            End Using ' commVB

            ' connBB إغلاق الاتصال الهدف
            connBB.Close()

        End Using ' connBB نهاية استخدام الاتصال الهدف

    End Using ' connVB نهاية استخدام الاتصال المصدر

    ff("################################" & vbNewLine & "# تم استيراد الاعضاء  عدد السجلات المضافة : " & (rowsCount) & vbNewLine & "################################")

End Sub



بالنسبة لترميزwindows-1256: لم أفهم أين واجهتك المشكلة!

(درس: حل مشكلة اللغة العربية عن التحويل إلى phpbb3)
.....
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
Reading from the stream has failed - بواسطة سعود - 12-10-14, 08:09 AM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 06:41 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 07:26 PM
RE: Reading from the stream has failed - بواسطة vbnet - 12-10-14, 08:14 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 09:15 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 09:27 PM
RE: Reading from the stream has failed - بواسطة vbnet - 12-10-14, 09:32 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 09:33 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 09:35 PM
RE: Reading from the stream has failed - بواسطة vbnet - 12-10-14, 09:47 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 10:14 PM
RE: Reading from the stream has failed - بواسطة vbnet - 12-10-14, 10:17 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 10:19 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 10:18 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 10:25 PM
RE: Reading from the stream has failed - بواسطة vbnet - 12-10-14, 11:28 PM
RE: Reading from the stream has failed - بواسطة سعود - 12-10-14, 11:47 PM
RE: Reading from the stream has failed - بواسطة سعود - 13-10-14, 01:43 AM
RE: Reading from the stream has failed - بواسطة سعود - 13-10-14, 03:42 AM
RE: Reading from the stream has failed - بواسطة vbnet - 14-10-14, 12:52 AM
RE: Reading from the stream has failed - بواسطة سعود - 14-10-14, 08:12 AM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم