2010-08-19 32 views

回答

1

服务器上的ODBC连接不会对您有所帮助。 ODBC连接需要在要连接的计算机上设置,而不是要连接到的计算机。

为了连接到dBASE文件(并将其看作一个数据库),你将需要

  1. 映射一个驱动器,以便您可以访问这些文件的位置..
  2. 连接使用OleDbConnection。

它还处理一个问题,你将有阅读来自.NET的DBase文件。如果您经常阅读它们,应用程序将开始抛出“System.Resources.Exceeded”异常。我发现唯一可靠的解决方案是杀死应用程序并重新启动它,这是在名为FixMyself的代码中完成的。 (不包括,因为它包含敏感数据)。 FixMyself例程基本上启动了第二个exe,它杀死了这个exe文件,然后重新启动它。

下面的示例代码是从生产代码复制的,应该给你一个push int他的正确方向。它映射驱动器,连接和读取。

这是丑陋的,但它的作品。这也只是部分的,因为它调用了这里没有包含的几个函数。但是,再次,它应该足以让你走。

Public Function GetRegisterConnectionString(ByVal PathToFolder As String) 
     Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & PathToFolder & ";Extended Properties=dBASE IV;User ID=Admin;Password=" 
    End Function 
    Public Sub ReadMyDbaseFile(ByVal DriveLetter As String, ByVal IPAddress As String) 

     Dim DpalmPath As String = "\\" & IPAddress & "\c$\Dpalm" 
     Dim cn As New System.Data.OleDb.OleDbConnection("") 
     cn.ConnectionString = Me.GetRegisterConnectionString(DpalmPath) 
     If ds.Tables.Contains("CurrentPrices") Then 
      ds.Tables.Remove("CurrentPrices") 
     End If 

    Dim POSAdapter As New System.Data.OleDb.OleDbDataAdapter("select * From MyDbaseFile WHERE SomeField > 0 AND ACTIVE = -1", cn) 

    Try 
     POSAdapter.Fill(ds, "CurrentPrices") 

    Catch ex As Exception 
     If InStr(ex.ToString().ToLower(), "system resource exceeded") Then 
      WriteToLog("System Resource Exceeded Error was thrown on register " & DriveLetter & ", IP " & IPAddress & ".") 
      Me.FixMyself() 
     Else 
      Throw New Exception(ex.ToString()) 
     End If 
    End Try 
    ds.Tables("CurrentPrices").Columns.Add("LastModified", GetType(Date)) 
    POSAdapter.Dispose() 
    POSAdapter = Nothing 
    cn.Dispose() 
    cn = Nothing 
    ds.AcceptChanges() 

    GC.Collect() 


End Sub 
+0

谢谢。如果您可以发布该代码,我会非常感激! – user204588 2010-08-19 20:17:45