同样代码,在不同机器上运行。其一通过,其二出错。请高手分析一下。
两部机器安装系统、软件相同。
在自家机器,使用VB6的 ADOX 编制创建数据库代码,编译运行均可以通过。
拿到办公室,运行,卡了。“实时错误 码 -2147024770”--自动化错误。工程中引用:Microsoft ADO Ext. 2.8 for DDL and Security
代码:Private Sub 查询表的字段属性()
  '
  Dim cat As New ADOX.Catalog
  Dim tbl As Table
  Dim Fld As ADOX.Column
  Dim pro As ADOX.Property
  Dim Cnns As String
  Dim ff As Integer
  Cnns = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\测试1.mdb;"
  cat.ActiveConnection = Cnns    '此行通不过,没有建立连接
  ff = FreeFile()
  Open "e:\测试1输出mdb格式.txt" For Output As #ff
  Print #ff, "文件名: E:\测试1.mdb"
  For Each tbl In cat.Tables
    Print #ff, "表名称=="; tbl.Name
    For Each Fld In tbl.Columns
      Print #ff, "字段Name=="; Fld.Name; _
                 " Type=="; Fld.Type; _
                 " DefinedSize=="; Fld.DefinedSize; _
                 " NumericScale=="; Fld.NumericScale; _
                 " Precision=="; Fld.Precision; _
                 " Attributes=="; Fld.Attributes
                 '" SortOrder=="; Fld.SortOrder
      'Debug.Print
      For Each pro In Fld.Properties
        Print #ff, "Property.Name=="; pro.Name; " Type=="; pro.Type; " Value=="; pro.Value; " Attributes=="; pro.Attributes
      Next pro
    Next Fld
  Next tbl
  Close #ff
End SubPublic Sub 创建数据库()
  Dim Cat As New ADOX.Catalog
  Dim Cnns As String
  Cnns = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & app.path & "\测试1.mdb"  '创建数据库
  Cat.Create Cnns      '此行通不过  set cat = Nothing
End Sub