3 Replies - 1387 Views - Last Post: 28 November 2012 - 03:30 PM Rate Topic: -----

#1 rleus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-November 12

Problems to open databaseconnection

Posted 19 November 2012 - 03:44 PM

Hello,

I'm having troubles with this piece of code.
I need to open my connection after clicking a button to add something to a database.
This goes fine for the first 2 times you try, the 3rd try will not open the database anymore.
Which causes a failure of the program I made.
I get an error on cnn.Open() that says OleDvException was unhandeled : unspecified error
Any help please...
 
    Sub subOpenConnection()
        'MessageBox.Show("subopenconnection")
        Dim strConn As String = ("Provider=Microsoft.ACE.OLEDB.12.0;" & _
                                  "Data Source = '" & fntPath() & "'")
        cnn = New OleDbConnection(strConn)
        If cnn.State = ConnectionState.Closed Then cnn.Open()
    End Sub



Many thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Problems to open databaseconnection

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Problems to open databaseconnection

Posted 20 November 2012 - 02:54 PM

The if statement it's irrelevant because you create a new object at the previous line, so whatever was related to cnn, disappears. If you take this road, make sure you close cnn after each usage so you don't have useless connection to your db.
if cnn.State = ConnectionState.Opened then 
   cnn.Close
end if 
cnn = new OledBConnection(strConn)



About the error, Inner exception is null or has more information for us?
Was This Post Helpful? 0
  • +
  • -

#3 rleus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-November 12

Re: Problems to open databaseconnection

Posted 21 November 2012 - 11:31 AM

I just tried what you said but it still won't work.
The piece of code u give makes it even unable to import anything from the database.
It is a complete unidentified error so no more details I'm afraid.

I've tried putting an cnn.Close() at the end of every class to be sure the connection will be closed, but still same error. A Try-Catch will also do no good.
This is the error I get, linked to cnn.Open()

Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 rleus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-November 12

Re: Problems to open databaseconnection

Posted 28 November 2012 - 03:30 PM

Hello,

I really can't find whats wrong in my code... tried several different possibilities for the code but they all give te same error.
But I got a crappy solution I think.
Is it possible to close your program and re-open the program automatically?
Becuase every time you restart the program you got 5 times of working input, then it stucks.
So: close => re-open another 5 times input.

If possible please give me the piece of code needed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1