DAO access error w.Ms Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to migrate my vb6.0 over to vb.net. Here is the error that that
I am stuck with:

Public myDB As DAO.Database
.....
path = System.IO.Path.GetFullPath("..")
myDB = WS.OpenDatabase(path & "\access.MDB", False, True)
'after I've created my workspace where WS is my workspace, I opend it up and
vb.net recognized it.
DeckUsers = dbCycDeck.OpenRecordset("USERS")
SQLString = "USERNAME = 'myLoginName'"
'so far so good up to this point. all of the sudden...error happens here:
DeckUsers.FindFirst(SQLString)

I know my ''myLoginName" name exists and it works fine in 6.0. I couldn't
figure this one. could someone please help, what did I do wrong? It
recognized my path, my db, all the way to my table, but it couldn't query?

I got this error:
"...
Run-time exception thrown : System.Runtime.InteropServices.COMException -
Operation is not supported for this type of object.
....."

Thanks.
 
Ben said:
I am trying to migrate my vb6.0 over to vb.net. Here is the error that that
I am stuck with:

Public myDB As DAO.Database
....
path = System.IO.Path.GetFullPath("..")
myDB = WS.OpenDatabase(path & "\access.MDB", False, True)
'after I've created my workspace where WS is my workspace, I opend it up and
vb.net recognized it.
DeckUsers = dbCycDeck.OpenRecordset("USERS")
SQLString = "USERNAME = 'myLoginName'"
'so far so good up to this point. all of the sudden...error happens here:
DeckUsers.FindFirst(SQLString)

I know my ''myLoginName" name exists and it works fine in 6.0. I couldn't
figure this one. could someone please help, what did I do wrong? It
recognized my path, my db, all the way to my table, but it couldn't query?

I got this error:
"...
Run-time exception thrown : System.Runtime.InteropServices.COMException -
Operation is not supported for this type of object.
...."

Thanks.

Do you not want to upgrade to ADO.NET? The com interop becomes expensive.

Chris
 
You know, Chris. It's be really nice if I could upgrade to ADO.NET but I
can't find the documents anywhere on how to works with Ms Access. However, i
couldn't find any documents on how to do that. Most books that teaches
ADO.net talks lots about web sql type of dB but nothing on local dB, like Ms
Access. Btw, what are the command, methods, procedure to open an Access file
and workspace? It'd be really nice if I could work ADO.NET cuz there aren't
too much codes to translate I could handle it.

Thanks.
 
Connection to an Access database using ADO.NET:


Dim con As OleDb.OleDbConnection
Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" &
Server.MapPath(relatvePathToDatabase)

con = New OleDb.OleDbConnection(conStr)
Dim cmdSQL As String = "SELECT blah FROM blah ORDER BY blah"
Dim cmd As New OleDb.OleDbCommand(cmdSQL, con)

Try
con.Open()

'Now, you have an open connection to your Access database and you
can use
'the Command object (cmd) to carry out its instructions. For
example:

'Generate an explicit DataReader from the command
Dim dr As OleDb.OleDbDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)

'Loop through the DataReader extracting each field called "Name"
If dr.HasRows Then
Do While dr.Read
'To examine the field value called "Name", you'd access it like
this: dr.Item("Name"))
Loop
End If

Catch ex As OleDb.OleDbException
'handle database generated exception here
Catch ex As OleDb.OleDbException
'handle all other exceptions here
Finally
con.Close()
End Try
 
wow. thanks, dude!

Scott M. said:
Connection to an Access database using ADO.NET:


Dim con As OleDb.OleDbConnection
Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" &
Server.MapPath(relatvePathToDatabase)

con = New OleDb.OleDbConnection(conStr)
Dim cmdSQL As String = "SELECT blah FROM blah ORDER BY blah"
Dim cmd As New OleDb.OleDbCommand(cmdSQL, con)

Try
con.Open()

'Now, you have an open connection to your Access database and you
can use
'the Command object (cmd) to carry out its instructions. For
example:

'Generate an explicit DataReader from the command
Dim dr As OleDb.OleDbDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)

'Loop through the DataReader extracting each field called "Name"
If dr.HasRows Then
Do While dr.Read
'To examine the field value called "Name", you'd access it like
this: dr.Item("Name"))
Loop
End If

Catch ex As OleDb.OleDbException
'handle database generated exception here
Catch ex As OleDb.OleDbException
'handle all other exceptions here
Finally
con.Close()
End Try
 
now, I can't logged into my database. it keeps telling me permission denied.

So I tried the visual way, by right clicked on "data connection" in explorer
windows. I selected MS Jet 4.0, clicked next, I pointed to the right file,
entered correct login name and password. then test connection, all looks
fine too me, but it keeps telling connection fail... blah blah. It's not
currently opened at all. The password / username is correct.

The thing is I normally opend my database by creating a workspace file in
DAO, then I insert my login name, password there. I can't opened my
workspace file here either. Could someone please help? Thanks.
 
Change the connection string to this:

Provider=Microsoft.JET.OLEDB.4.0;Data Source=" &
Server.MapPath(relatvePathToDatabase) & ";User
Id=ADDIDHERE;Password=ADDPASSWORDHERE"
 

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

Back
Top