Results 1 to 24 of 24

Thread: Lost Connection to MySQL server during query

  1. #1

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Lost Connection to MySQL server during query

    I am using MySQL server 3.51 database. I am insert/update image into database as follow;
    VB Code:
    1. Private Sub insertupdate_image()
    2.     Dim MyStream As ADODB.Stream
    3.     Set MyStream = New ADODB.Stream
    4.     MyStream.Type = adTypeBinary
    5.     MyStream.Open
    6.     MyStream.Position = 0
    7.    
    8.     Dim sTemp As String
    9.     Dim MyData As Variant
    10.        
    11.     sTemp = "C:\SPAI_Temp\HMDaftar" & intHMDaftarID & ".jpg"
    12.     If pPicture = 0 Then Exit Sub
    13.     VB.SavePicture pPicture, sTemp
    14.     MyStream.LoadFromFile sTemp
    15.  
    16.     Dim Rs As ADODB.Recordset
    17.     Set Rs = New ADODB.Recordset
    18.     query = "Select Gambar,HMDaftarID From t_HMGambar where HMDaftarID=" & intHMDaftarID
    19.     Rs.Open query, db, , adLockPessimistic
    20.    
    21.     With Rs
    22.         If .RecordCount > 0 Then
    23.             .Fields!Gambar = MyStream.Read
    24.             .Fields!HMDaftarID = intHMDaftarID
    25.             .Update
    26.         Else
    27.             .AddNew
    28.             .Fields!Gambar = MyStream.Read
    29.             .Fields!HMDaftarID = intHMDaftarID
    30.             .Update
    31.         End If
    32.         .Close
    33.     End With
    34.  
    35.     MyStream.Close
    36.     Set MyStream = Nothing    
    37. End Sub

    It is work well if I insert or update image that size below then 30Kb.

    BUT, it is giving "Lost Connection to MySQL server during query" error if I insert or update image that the size above 30Kb.
    What should I do?

    Thanks
    Last edited by g-mie; Jan 14th, 2007 at 10:46 PM.

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Set your connection timeout to 600

  3. #3

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    randem...

    I'm very new with MySQL (3.51). How to set Connection Timeout to 600?

    Thanks

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    You set it on you ADODB connection.

  5. #5
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    396

    Re: Lost Connection to MySQL server during query

    Hi g-mie;

    MySQL is way out of my league, but just to satisfy my own curiosity about MySQL could you tell me what data type you are using to store your pictures. It seems odd that MySQL would crash like that.

  6. #6

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    LinXG...
    Field Name = MyPic
    Field Type = LongBlob
    Length/Set = ""
    Default = ""

  7. #7

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    randem...
    Please tell me more detail....
    TQ

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Lost Connection to MySQL server during query

    Try setting the CommandTimeout property to a higher value not the ConnectionTimeout property.

    db.CommandTimeout = 60 'or whatever you need. default is 30 seconds.

  9. #9

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    brucevde...
    Same error still come out.
    Any others idea?

  10. #10

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    anybody?

  11. #11
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    You store pictures in a field that supports long data types (binary information) such as IMAGE.

  12. #12

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    I use LongBlob field type. I think it is suitable field type. Maybe other setting need to be set..!?
    Any idea?

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Should work. All you need is a simple test to be sure
    VB Code:
    1. If (Not dbTable!Data.Attributes And FieldAttributeEnum.adFldLong) Then
    2.  
    3. ... 'Field is ok for long binary data
    4.  
    5. End If

  14. #14
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Can you post your project... or at least your connection code?

  15. #15
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Also why are you attempting to use streaming data instead of the regular recordset method?

  16. #16

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    Quote Originally Posted by randem
    Can you post your project... or at least your connection code?
    This is my connection code

    VB Code:
    1. Public Sub conn2db()
    2. Dim con As String
    3. mServer = "localhost"
    4. con = "DRIVER={MySQL ODBC 3.51 Driver};" _
    5.             & "SERVER=" & mServer & ";" _
    6.             & "DATABASE=Kejora;" _
    7.             & "UID=root;" _
    8.             & "PWD=pass;" _
    9.             & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 163841
    10.  
    11. Set db = New ADODB.Connection
    12. db.CursorLocation = adUseClient
    13. db.Open con
    14.  
    15. End Sub
    Last edited by g-mie; Jan 19th, 2007 at 02:37 AM.

  17. #17

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    Quote Originally Posted by randem
    Also why are you attempting to use streaming data instead of the regular recordset method?
    If I not mistaken, streaming can 'hold' big size of data.

  18. #18
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Use:
    VB Code:
    1. Public Sub conn2db()
    2. Dim con As String
    3. mServer = "localhost"
    4. con = "DRIVER={MySQL ODBC 3.51 Driver};" _
    5.             & "SERVER=" & mServer & ";" _
    6.             & "DATABASE=Kejora;" _
    7.             & "UID=root;" _
    8.             & "PWD=pass;" _
    9.             & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 163841
    10.  
    11. Set db = New ADODB.Connection
    12. db.CursorLocation = adUseClient
    13. db.ConnectionTimeout=600
    14.  
    15. db.Open con
    16.  
    17. End Sub
    Last edited by randem; Jan 19th, 2007 at 02:46 AM.

  19. #19

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    Quote Originally Posted by randem
    db.ConnectionTimeout=600
    Same error come out.
    VB Code:
    1. If .RecordCount > 0 Then
    2.             .Fields!Gambar = MyStream.Read
    3.             .Fields!HMDaftarID = intHMDaftarID
    4.             .Update                     '<==the error highlighted here
    5.         Else
    6.             .AddNew
    7.             .Fields!Gambar = MyStream.Read
    8.             .Fields!HMDaftarID = intHMDaftarID
    9.             .Update
    10.         End If
    Last edited by g-mie; Jan 19th, 2007 at 03:01 AM.

  20. #20
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    I am not sure you can update a Database field like that. You would need to use the AppendChunk method.

  21. #21

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    BUT, it is working for picture with size below then 30KB.
    AND, it is working if I use MS-Access database. I can insert picture with size more then 2MB

  22. #22
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Is your access database on your local computer and mySQL over a network or internet?

  23. #23
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Lost Connection to MySQL server during query

    Here is something I goggled:

    While logged into MySQL, we should modify the max_allowed_packet system variable. This variable determines how large of a packet (i.e. a single row) can be sent to the MySQL server. By default, the server will only accept a maximum size of 1 meg from our client application. If you do not intend to exceed 1 meg, this should be fine. If you do intend to exceed 1 meg in your file transfers, this number has to be increased. I set my max_allowed_packet value to 15M, in MySQL 3.x, this limit is 16M, in 4.x, the size is limited only to your system memory, up to a theoretical 2G maximum. I personally find 15M to be more than enough, especially since my users connect remotely through DSL modems at best, and a 15 meg transfer tends to take upwards of 5 minutes as it is. If you do need to change this value, you can either set it in the my.cnf file (add a line that reads max_allowed_packet=15M), or use the SET max_allowed_packet=15M; syntax from within MySQL.

  24. #24

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Re: Lost Connection to MySQL server during query

    Thanks randem...
    It's work now. The come from max_allowed_packet.
    TQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width