Help: System.Data.OleDb.OleDbException Error

G

G.Esmeijer

Friends,

The following code works fin. BUT...
after a >> couple times<< this code is used is a class it comes with an
error saying
unhandled System.Data.OleDb.OleDbException' occurred in system.data.dll


Any suggestions what could be wrong.

public int LeesRadSoort( string radcode ) {

string sSQL = "SELECT * FROM Rad WHERE RadCode = '" + radcode + "';";

OleDbConnection cnnSCORE = new OleDbConnection();

cnnSCORE.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
source= C:\Scorwin\data \Data.mdb";

cnnSCORE.Open();

OleDbCommand cmdSQL = new OleDbCommand(sSQL, cnnSCORE);

OleDbDataReader sdrSCORE = cmdSQL.ExecuteReader();

/// code that is making some calculations -> result

CnnSCORE.Close();

return result

}



Regards

gerrit esmeijer

(Netherlands)
 
F

Frans Bouma [C# MVP]

G.Esmeijer said:
Friends,

The following code works fin. BUT...
after a >> couple times<< this code is used is a class it comes with an
error saying
unhandled System.Data.OleDb.OleDbException' occurred in system.data.dll


Any suggestions what could be wrong.

public int LeesRadSoort( string radcode ) {

string sSQL = "SELECT * FROM Rad WHERE RadCode = '" + radcode + "';";

OleDbConnection cnnSCORE = new OleDbConnection();

cnnSCORE.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
source= C:\Scorwin\data \Data.mdb";

cnnSCORE.Open();

OleDbCommand cmdSQL = new OleDbCommand(sSQL, cnnSCORE);

OleDbDataReader sdrSCORE = cmdSQL.ExecuteReader();

/// code that is making some calculations -> result

CnnSCORE.Close();

return result

}

enclose the ExecuteReader() statement with a try/catch clause andCatch the
OleDbException. In that exception, you'll find an Errors collection which
contains the actual error. See the OleDbException docs for details. By
checking this collection, you can determine what's wrong.

FB
 
G

G.Esmeijer

Frans,

Thanks for your reply... however, in spite of the fact that I have done what
you suggested, this error is not caught by the try catch construction. I
keeps pointing at the same line and the error is not caught. Thanks anyway

Gerrit Esmeijer
 
F

Frans Bouma [C# MVP]

G.Esmeijer said:
Frans,

Thanks for your reply... however, in spite of the fact that I have done what
you suggested, this error is not caught by the try catch construction. I
keeps pointing at the same line and the error is not caught. Thanks anyway

What's the code after you've enclosed the code with try/catch statements? If
the code you originally posted throws an OleDbException, it has to end up in
the catch. Did you position the try statement at the right spot? Could you
post that snippet with the try/catch?

Frans.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top