FIX: "Can't Save" Error Occurs When You Try to Save an ADO Recordset to a File (818518)



The information in this article applies to:

  • ActiveX Data Objects (ADO)
  • Microsoft Data Access Components

SYMPTOMS

When you try to save an ADO recordset to a file that was created by another user of the system, you may receive the following error message:
Run-time error '-2147286781 (80030103)':
Can't save.
You receive this error message if the application is in a read-only folder, even if the recordset file is in a folder that has write permissions for both users.

CAUSE

When you try to save the recordset to a file that already exists, the recordset object creates a temporary file in the folder of the application. This folder is a read-only folder. Therefore, the second user cannot overwrite the source file.

RESOLUTION

This problem is resolved in Microsoft Data Access Components (MDAC) 2.8. In MDAC 2.8, the ADODB recordset creates the temporary file in the same folder as the destination file that was used to save the recordset.

To download Microsoft Data Access Components (MDAC) 2.8, visit the following Microsoft Web site:Note Microsoft recommends that you test your application with MDAC 2.8 in a test environment first, to make sure that you are aware of any compatibility issues before you decide to use (or upgrade to) the MDAC 2.8 version.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in MDAC 2.8.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Basic 6.0.
  2. On the File menu, click New Project. In the New Project dialog box, click Standard Exe. By default, Form1 is created.
  3. On the Project menu, click References. Click Microsoft ActiveX Data Objects 2.7 Library, and then click OK.
  4. Add two Command buttons to the form.
  5. Right-click Form1, click View Code, and then add the following code:
    Option Explicit
    
    Private Sub Command1_Click()
       Dim cn As New Connection
       Dim rs As New Recordset
    
       On Error GoTo ErrHandler
       cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=YourSQLServer"
       cn.Open
          
       ' Open the RecordSet
       rs.Open "SELECT * FROM CUSTOMERS", cn, adOpenDynamic, adLockPessimistic
       
       ' Persist the RecordSet
       rs.Save "C:\Documents and Settings\NonAdminUserName\My Documents\Customer.dat"
       
       Exit Sub
       
    ErrHandler:
       MsgBox "Error : " & Err.Description
    End Sub
    
    Private Sub Command2_Click()
       Dim rs As New ADODB.Recordset
       
       On Error GoTo ErrHandler:
       
       ' Read the Persisted RecordSet
       rs.Open "C:\Documents and Settings\NonAdminUserName\My Documents\Customer.dat"
       
       ' Save the RecordSet
       rs.Save "C:\Documents and Settings\NonAdminUserName\My Documents\Customer.dat"
       
       Exit Sub
    
    ErrHandler:
       MsgBox "Error Number: " & Err.Number
       MsgBox "Error Description: " & Err.Description
    End Sub
    
    Private Sub Form_Load()
       Command1.Caption = "Persist RecordSet"
       Command2.Caption = "Reload Data"
    End Sub
    
  6. Replace "YourSQLServer" in the connection string with the name of your SQL Server.
  7. Save the project in the C:\Program Files\Test folder.
  8. On the Run menu, click Start.
  9. Click Persist RecordSet, and then click Reload Data. No error occurs.
  10. Log on to the computer as a non-administrator user (by default, non administrators do not have write access to the C:\Program Files\ folder).
  11. Run the project again. You receive the error message that is described in the "Symptoms" section.

REFERENCES

For more information about Microsoft Data Access Technologies, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/1/2003
Keywords:kbProgramming kbDataObject kbfix KB818518 kbAudDeveloper