Microsoft KB Archive/247662

From BetaArchive Wiki
Knowledge Base


How To Access a Secured Jet Database Through the MSDataShape Provider

Article ID: 247662

Article Last Modified on 6/29/2004



APPLIES TO

  • Microsoft ActiveX Data Objects 2.1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition



This article was previously published under Q247662

SUMMARY

The Migrating from DAO to ADO white paper discusses how to open a secured Jet database through ActiveX Data Objects (ADO). However, the method illustrated cannot be used when opening the database through the MSDataShape provider.

MORE INFORMATION

The white paper uses the following code to illustrate opening a Microsoft Jet database that has user security applied:

cnn.Provider = "Microsoft.Jet.OLEDB.4.0" 
cnn.Properties("Jet OLEDB:System database") = "c:\sysdb.mdw" 
cnn.Open "Data Source=c:\nwind.mdb;User Id=Admin;Password=password;" 
                

However, you will receive run-time error 3265:

"The item cannot be found in the collection corresponding to the requested name or ordinal"

if you try to apply the following code to use the MSDataShape provider:

cnn.Provider = "MSDataShape" 
cnn.Properties("Jet OLEDB:System database") = "c:\sysdb.mdw" 
cnn.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;User Id=Admin;Password=password;" 
                

The error occurs because the "Jet OLEDB: System Database" property is provider-specific. The MSDataShape provider does not expose the property.

To open the secured database correctly, use the following code:

cnn.Provider = "MSDataShape" 
cnn.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;User Id=Admin;Password=password;Jet OLEDB:System Database=c:\sysdb.mdw" 
                

-or-


cnn.Open "Provider=MSDataShape;Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;User Id=Admin;Password=password;Jet OLEDB:System Database=c:\sysdb.mdw" 
                

To open a database secured with a database password, use the following code:

cnn.Open "Provider=MSDataShape;Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;Jet OLEDB:Database Password=DBPassword"
                

To open a database secured with both a database password and a user password, use this code:

cnn.Open "Provider=MSDataShape;Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;User Id=Admin;Password=password;Jet OLEDB:System Database=c:\sysdb.mdw;Jet OLEDB:Database Password=DBPassword"
                

Keywords: kbhowto kbmdacnosweep KB247662