Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i grab data from an Access DB with READ permissions ONLY? 1

Status
Not open for further replies.

OrangeWire

IS-IT--Management
Mar 26, 2003
28
US
I have a simple VB app that pulls data from a DB (access .mdb file not a server) and throws it on a datagrid. It works fine for me (i have read/write access) but for someone with read ONLY it craps out and gives all kinds of errors.

Im using the following to connect:

OleDbConnection1 > OldDbDataAdapter1 > DataSet11

Thanks a LOT for your time guys!
 
use a datareader instead of a dataset. it is faster, and is readonly. is that what you are asking?
 
Yes i think thats what im asking. i am VERY new to vb.

I am having problems getting it to dump the data to a datagrid.

Here si the code im using:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbConnection1.Open()
'Dim Reader As System.Data.OleDb.OleDbDataReader
'Reader = OleDbCommand1.ExecuteReader()
DataGrid1.DataSource = OleDbCommand1.ExecuteReader()Reader
'DataGrid1.DataBind()
Reader.Close()
OleDbConnection1.Close()
End Sub



Any ideas?

Thanks very much for responding!
 
sorry, i think i made a mistake. you cannot bind a windows form control to a datareader, but you can bind to a web form control. sorry. tell you waht, you can use a dataset to grab the data. it shouldn't matter what the user does to it, you'd have to save the dataset back to the db for the changes to take effect (that is if you use a disconnected dataset). try this:


establish a connected object (lets call it conn), and in your form try this:

private daMyAdapter as new OleDb.OleDbDataAdapter
private dsMyDataset as new dataset
private strSQL as string

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strSQL = "Select * from TableName"
daMyAdapter = new oledb.oledbDataadapter(strSQL, conn)
daMyAdapter.fill(dsMyDataset, "TableName<or other name>")

myDatagrid.datasource = dsMyDataset.Tables("TableName<or other name>")
myDatagrid.ReadOnly = True 'or something similar

end sub





Does this help at all????



 
Hey thank you very much.

I think i found the problem though and it really is beyond what i posted.

Basically the db is a .mdb file stored on a share that only a select few poeople have write access to.

The vb application can get into the DB fine and pull data for us with r/w permissions on the share with no prob BUT when someone who doesnt have Write permissions trys to access the DB, the db trys to write out its lock file and cant because the person is not allowed to write to the share thus causing probs and crashing the app.


if you have ANY idea how to get around this i would love to hear your input.

Thanks a Lot for your help man, its much appreciated.
 
you can surround the write to db section of code with a try catch block. you can put a messagebox in the catch block that says something like "you cannot write to this db" or something. the app will not crash, the user can read the data, but they will not be able to write to it.

i think that is what you want right? otherwise, if you want everyone to access the db, you need to put it in a public share.


Also, FYI - two people (or apps) cannot access the same mdb at the same time. mdb's are one at a time ONLY. you you don't like this functionality, you can put the db in a sql server db, or some other db, or try to create an Access adp file (Access Data Project - i think that's what it stands for). adp's allow multiple users up to the limit of the share (if the share allows only 5 users connected, then only 5 can access the adp).


does this help at all?
 
Hayt,

an mdb can support multiple apps at a time but no more then 5 at a time. Adp"s are there to connect to MSDE or sql-server and are only for interface purposes they don't contain data.

Orangewire,
yes I do think you have a problem an mdb needs the ldb to work
you should add this to the connection string

Mode=Share Deny Write

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Also, by leave connections open for the smallest possible period of time you can go beyond the 5 connection limit. By keeping your connections open only for the split seconds it takes to pull down data or to send an update query you can reduce the risk of having more then 5 people actually connected at once, and run more users. Theoreticly it is still possible to hit the 5 connect limit though, so code accordingly.

-Rick

----------------------
 
christiaan

i didn't know that mdb's allow up to 5 connections. i haven't done it in years, and more than likely, i was thinking about another db anyway. thanks. i'll stick to stuff i know from now on
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top