Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Problem using DAO on Server 2003

To speed up working with network files for remote users they can connect via a "Terminal Server" (Windows Server 2003). Reading/writing data in Ms Access 2003 from Excel 2003 via VBA Automation works fine where ADO is used but not with routines using DAO (my conclusion). Errors like 7866 "Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user" occur. I have set all references I think is needed.
When not connected via Server 2003 everything works fine.
Is this a bug or is there a workaround other than change the code to ADO?
[597 byte] By [RolfG] at [2007-11-11 10:28:24]
# 1 Re: Problem using DAO on Server 2003
That error usually indicates that either someone else has opened the file for exclusive use, or the user opening the file does not have sufficient permissions to the folder where the file is located.

Users must have full permissions to the folder where the database is located so that the corresponding .LDB file can be created, updated and deleted.
pclement at 2007-11-11 23:43:16 >
# 2 Re: Problem using DAO on Server 2003
Thanks Paul for responding!
I guess it is not a permission issue because I can easly open the Access file myself with DAO when not using the Terminal Server (Server 2003). Besides there is no *.ldb file present at the database location. To my understanding the combination Server 2003 and DAO is the problem. Any further suggestion?
RolfG at 2007-11-11 23:44:22 >
# 3 Re: Problem using DAO on Server 2003
I'm not sure what the difference is between ADO and DAO under Terminal Server. Are you opening the database for read-only access? The .LDB file is always created when an Access database is opened for write access, and deleted when the last connection to the database is closed.
pclement at 2007-11-11 23:45:17 >
# 4 Re: Problem using DAO on Server 2003
As an example I have this code:

Set AccessDB = New Access.Application
AccessDB.OpenCurrentDatabase strLedgerFullName '(strLedgerFullName =database path
If Err then Debug.Print Err.number & Err.Description

The error occurs already here!
RolfG at 2007-11-11 23:46:23 >
# 5 Re: Problem using DAO on Server 2003
OK, well that example uses the Microsoft Access object model. It isn't the same as using the DAO OpenDatabase method.

If you use OpenDatabase does the error occur? Perhaps it's an issue with using the Microsoft Access object model and not DAO.
pclement at 2007-11-11 23:47:27 >
# 6 Re: Problem using DAO on Server 2003
I think you are right! I have a number of sub's where DAO is used and when I test more accurately I see that they run well. In some sub's I try to open the database
with code as given above which generates the mentioned error. Changing to "AccessDB.OpenDatabase strLedgerFullName" gives error 438 (Object doesn't support this property or method". So what's wrong then?
RolfG at 2007-11-11 23:48:26 >
# 7 Re: Problem using DAO on Server 2003
The example you have given, tries to have exclusive access to the database and since their are other users opening the same Access database, exception occurs.
I found this code on Microsoft website, which illustrates both opening Access database exclusively and read only:

Sub OpenDatabaseX()

Dim wrkJet As Workspace
Dim dbsNorthwind As Database
Dim dbsPubs As Database
Dim dbsPubs2 As Database
Dim dbsLoop As Database
Dim prpLoop As Property

' Create Microsoft Jet Workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

' Open Database object from saved Microsoft Jet database
' for exclusive use.
MsgBox "Opening Northwind..."
Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _
True)

' Open read-only Database object based on information in
' the connect string.
MsgBox "Opening pubs..."

' Note: The DSN referenced below must be set to
' use Microsoft Windows NT Authentication Mode to
' authorize user access to the Microsoft SQL Server.
Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
dbDriverNoPrompt, True, _
"ODBC;DATABASE=pubs;DSN=Publishers")

' Open read-only Database object by entering only the
' missing information in the ODBC Driver Manager dialog
' box.
MsgBox "Opening second copy of pubs..."
Set dbsPubs2 = wrkJet.OpenDatabase("Publishers", _
dbDriverCompleteRequired, True, _
"ODBC;DATABASE=pubs;DSN=Publishers;")

' Enumerate the Databases collection.
For Each dbsLoop In wrkJet.Databases
Debug.Print "Database properties for " & _
dbsLoop.Name & ":"

On Error Resume Next
' Enumerate the Properties collection of each Database
' object.
For Each prpLoop In dbsLoop.Properties
If prpLoop.Name = "Connection" Then
' Property actually returns a Connection object.
Debug.Print " Connection[.Name] = " & _
dbsLoop.Connection.Name
Else
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop
End If
Next prpLoop
On Error GoTo 0

Next dbsLoop

dbsNorthwind.Close
dbsPubs.Close
dbsPubs2.Close
wrkJet.Close

End Sub
unhitchedjet at 2007-11-11 23:49:24 >
# 8 Re: Problem using DAO on Server 2003
Changing to "AccessDB.OpenDatabase strLedgerFullName" gives error 438 (Object doesn't support this property or method". So what's wrong then?

The Access object model does not use OpenDatabase. I just wanted you to check to see if DAO worked properly (using OpenDatabase).

If DAO and OpenDatabase works then I think we've narrowed it down to an automation issue.
pclement at 2007-11-11 23:50:27 >
# 9 Re: Problem using DAO on Server 2003
Yes I noticed OpenDataBase isn't an Access object. I use OpenDatabase with DAO in other functions and it seems to run well with the same database.
So, let's face it: Our database is located on our "ordinary" cluster server (CS). Opening it the "normal way with the simple code:

Set AccessDB = New Access.Application
With AccessDB
.OpenCurrentDatabase strOverviewLedgerFullName
.DoCmd.OpenForm strForm, , , "BusinessUnit = '" & strLedgerGroup & "'"
.Visible = True
End With

works well buit takes a long time when working at a distance. Therefore we introduced the Terminal Server (TS) to speed up things. When connected to TS the code above fails.
As you probably know, when connected to TS, the Office applications run on the server and not on the user client computer. TS is "only" sending the screen picture to the client computer which means faster action.
Does this help you to understand what difference there might be betw. the two options?
I looked for a solution to open a database form or table to the screen vith DAO or ADO model but did not find any at the first glance.
RolfG at 2007-11-11 23:51:29 >
# 10 Re: Problem using DAO on Server 2003
Give the following a try to see if it makes any difference:

Dim db As DAO.Database
Set AccessDB = New Access.Application
With AccessDB
.Visible = True
Set db = .DBEngine.OpenDatabase(strOverviewLedgerFullName, False, False)
.OpenCurrentDatabase strOverviewLedgerFullName
.DoCmd.OpenForm strForm, , , "BusinessUnit = '" & strLedgerGroup & "'"
db.Close
Set db = Nothing
End With
pclement at 2007-11-11 23:52:27 >
# 11 Re: Problem using DAO on Server 2003
Thank you Paul for not giving up!
I tested your code when connected to CS (see previous input) and it works fine. But on TS I have the same problem as before. I noticed the following:
Having executed the line
Set db = .DBEngine.OpenDatabase(strOverviewLedgerFullName, False, False)
a *.ldb file is created on the database folder.

At line
.OpenCurrentDatabase strOverviewLedgerFullName
Error 7866 "Microsoft Office Access can't open the database because it is missing, or opened exclusively by another user"
makes the fun come to an end.
Strange, isn't it? Any idea what to test next?
RolfG at 2007-11-11 23:53:31 >
# 12 Re: Problem using DAO on Server 2003
OK, let's test something here. Try adding the Exclusive parameter for OpenCurrentDatabase and set it to False:

.OpenCurrentDatabase strOverviewLedgerFullName, False
pclement at 2007-11-11 23:54:29 >
# 13 Re: Problem using DAO on Server 2003
Paul, no success I'm afraid.

To avoid possible conflict with other code in my files, I opened a new Excel file and entered some code there to test opening a form in Northwind.mdb. Normally on a Terminal Server you can not see your own C drive. In our case we have mapped the user's C drive to "L" on TS whilst the "C" seen when connected to TS is the C on TS. Pse compare the results below:
-----------
Dim AccessDB As Access Application
-----------
Sub DisplayForm()
Dim db As DAO.Database, strDBFullName As String
Set AccessDB = New Access.Application
strDBFullName = "L:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb"
With AccessDB
.Visible = True
Set db = .DBEngine.OpenDatabase(strDBFullName, False, False)
.OpenCurrentDatabase strDBFullName
DoCmd.OpenForm "Orders"
db.Close
Set db = Nothing
End With
End Sub

At the line '.OpenCurrentDatabase strDBFullName', I get error 7866 (same as earlier)

Changing the second code line to this:
strDBFullName = "C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb"
I get error 3051 (The Microsoft Jet Database engine cannot open the file 'see string above'. It is already opened exclusively by another user, or you need permission to view its data.)
but this time the error occurs at line
'Set db = .DBEngine.OpenDatabase(strDBFullName, False, False)'

If I first open Access I can open the database manually, although via TS-C:\ it is ReadOnly, which is expected because its C is write protected.
Is this of any help to understand the reason for the strange behaviour?
_________________
Rolf
RolfG at 2007-11-11 23:55:36 >
# 14 Re: Problem using DAO on Server 2003
OK, now you've really got me scratching my head so I need to ask a question. When you logon through Terminal Server, do you have write access to the resource (e.g. folder) where the database file is located?
pclement at 2007-11-11 23:56:35 >
# 15 Re: Problem using DAO on Server 2003
According to my colleagues in our IT support group the read/write rights are set on the folder(s) where the database is located and it does not matter whether I connect through the Terminal Server or direct to the Cluster Server (where all or network files are saved, including the database).
And I have the right to edit the database, which I do regularly.
Remember also that I can connect and edit with DAO and ADO statements although I initially thought DAO was the problem - which was a mistake, sorry for that!
_____________________________________________
Rolf
RolfG at 2007-11-11 23:57:33 >
# 16 Re: Problem using DAO on Server 2003
So just to confirm, you can do the following without any issues:

1) Logon through Terminal Server
2) In the Terminal Server session manually run Microsoft Access
3) Click on the File...Open menu item in Microsoft Access
4) Select your file from the folder in the Open dialog box
5) Then click on the down arrow of the Open button and select Open
6) Database then opens in Microsoft Access without any errors and you can make changes to it

Is this correct?
pclement at 2007-11-11 23:58:37 >
# 17 Re: Problem using DAO on Server 2003
The answer to all 6 issues is yes.
But I think the problem is solved now. I handed over the Northwind script to our admin. and he had no problem to open the database form! After having rebooted the server it works also for me and for other users I hope! So, after all it was kind of a permission issue I think, I do not know the details yet.
I appreciate your interest and patience in helping me to find a solution to my dilemma!
_______________________________________________________________________
Rolf
RolfG at 2007-11-11 23:59:31 >