Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Access database on read only/Access controlled network 200 POINTS!!

Question is similar to http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20409655.html

I have a vb app that needs to access an Access 2000 database on a network controlled Read Only directory.  The admin will not allow me to set any directory to read/write, so that is not an option.  According to the accepted answer at

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20409655.html

I would not be able to programatically open this database.  I only want to read values from it, that's it.  If this is not possible in a read only directory, how is it possible that I can open that same read only database in the read only directory by just clicking on it and opening it in Access?  Should't I not be able to open it either if it needs that ldb file?  There's got to be a  way to systematically program this! Thanks!
0
mchandler
Asked:
mchandler
  • 3
  • 3
1 Solution
 
EDDYKTCommented:
I think you can do that by setting

Dim Cn As ADODB.Connection, DSN As String
   
If Cn Is Nothing Then Set Cn = New ADODB.Connection
Cn.Mode = adModeRead    ' set cn to readonly
Cn.Open DSN ' where dsn is your dsn less

0
 
EDDYKTCommented:
I use following routine and return the record set


Public Function ReadRecordSet(ByVal DSN As String, ByVal SelectList As String) As ADODB.Recordset
    Dim Cn As ADODB.Connection
   
    On Error GoTo Connection_Failed
    If Cn Is Nothing Then Set Cn = New ADODB.Connection
    Cn.Mode = adModeRead
    Cn.Open DSN
    Dim RS As ADODB.Recordset
   
    Set RS = New ADODB.Recordset
    RS.CursorLocation = adUseClientBatch
    On Error GoTo Read_Failed
    RS.Open SelectList, Cn, adOpenKeyset, adLockBatchOptimistic, adCmdText
    Set RS.ActiveConnection = Nothing
    Set ReadRecordSet = RS
    Set RS = Nothing
    If (Not Cn Is Nothing) Then Set Cn = Nothing
    Exit Function
   
Read_Failed:
    If (Not Cn Is Nothing) Then Set Cn = Nothing
    If Not RS Is Nothing Then Set RS = Nothing
   
Connection_Failed:
    Err.Raise Err.Number, "ReadRecordSet", Err.Description
End Function
0
 
mchandlerAuthor Commented:
this is what I have put in my code, and I got the message:

Could not lock file.
error number: -2147467259

Thanks again.
Matt



 Dim conImex As Connection
 Dim rsImex As Recordset
   
  Set conImex = New Connection
  Set rsImex = New Recordset
   
 'Establish connection string and open connection
  conImex.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database.mdb;Mode=Read;Persist Security Info=False"
  conImex.Open
   
 'SQL statement
  strSQL = "SELECT * From tblMaps"
       
  rsImex.CursorLocation = adUseClientBatch
  rsImex.Open strSQL, conImex, adOpenKeyset, adLockBatchOptimistic, adCmdText
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
EDDYKTCommented:
Try this

Dim conImex As Connection
Dim rsImex As Recordset
   
 Set conImex = New Connection
 Set rsImex = New Recordset
 
conImex.Mode = adModeRead

'Establish connection string and open connection
conImex.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\Database.mdb;"

conImex.Open
0
 
mchandlerAuthor Commented:
I took a sick day today, but this seemed to work in a read only directory at home.  I'll try it tommorow morning, and award you the points.  Thanks again for your quick and kind help.


  Dim conImex As Connection
  Dim rsImex As Recordset
   
  Set conImex = New Connection
  Set rsImex = New Recordset
     
  conImex.Mode = adModeRead
  conImex.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\Database.mdb;"
  conImex.Open

  strSQL = "SELECT * From tblMaps"  

  rsImex.Open strSQL, conImex, adOpenForwardOnly, adLockReadOnly
0
 
mchandlerAuthor Commented:
Thank you for your quick help....it worked! I am giving you an A!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now