Results 1 to 7 of 7

Thread: database connection closes my form automatically

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    109

    database connection closes my form automatically

    I have a piece of code connecting to my database retrieving data. I was just testing the form on another computer and everytime it loads this specific form it closes the form. Anyone know why it would do that?

    You can see the lines I had to comment out in order for the form to NOT close on load. Is there something possibly that needs to be installed on this other computer? running XP pro 32 bit.

    Code:
            Dim conn As OleDbConnection
            Dim comm As OleDbCommand
            Dim dr As OleDbDataReader
            Dim connectionString As String
            Dim sql As String
            connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;"
            sql = "SELECT * FROM table WHERE ID = (SELECT MAX(ID) FROM table)"
            conn = New OleDbConnection(connectionString)
            'conn.Open()
            comm = New OleDbCommand(sql, conn)
            'dr = comm.ExecuteReader()
            'conn.Close()
            'dr.Close()
            comm.Dispose()
            conn.Dispose()

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: database connection closes my form automatically

    Did you try an place this in a Try Catch block and show the error message?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    109

    Re: database connection closes my form automatically

    Thanks! I've never used that before.

    I get this error

    Could not load file or assembly 'System.EnterpriseServices.Wrapper.dll' or one of its dependencies. The system cannot find the path specified.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: database connection closes my form automatically

    OK now do you know how to set break points and step though code? That way you can see on what line it fails.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    109

    Re: database connection closes my form automatically

    no, Iver never done that before. Is it easy to tell me how?

    Also, I should say the issue is now fixed. I reinstalled the .net framework 2.0 and I don't get the error anymore. Thank you for telling me about the try/catch block

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: database connection closes my form automatically

    Read here for a starting on degugging.... If you progress in programming you will need to understand how to do this.


    http://blogs.msdn.com/sburke/archive...urce-code.aspx
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    109

    Re: database connection closes my form automatically

    Thanks, I appreciate the help!

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