Search code examples
sql-server-2016dbf

dBaseIV file creation from SQL Server 2016 database


I have a requirement as follows: on click of a link button on a web page, I have to fetch some records from a SQL Server 2016 database and convert them into dBaseIV format (.env, .ad1, .ad2, .veh) files and show a download/save as popup on the page where the end user would be able to download the files individually.

Any leads would be appreciated.

dBaseIV files expected on click of link button


Solution

  • This is like 90's requirement - a lot from memory ...

    This is a VS 2017 console app ..., creates a DBaseIV file called bill and inserts a record, of course the logic to create, read etc is not included - also

    • System.IO.File.Exists is of dubious reliability on 64bit systems - someone else might have a better solution
    • I don't use IIS - so no idea on how to setup downloads there
    • and - I ran this on a Dell Windows 10 machine, the dBaseIV driver existed in ODBC

      Module Module1

      Sub Main()
          Dim connectionString As String = "Driver={Microsoft dBase Driver (*.dbf)};DBQ=C:\temp\"
          Using cn As New Odbc.OdbcConnection(connectionString)
      
              cn.Open()
      
              If Not System.IO.File.Exists("C:\Temp\books.dbf") Then
                  Using cmd As New Odbc.OdbcCommand("CREATE TABLE BOOKS (title char(50))", cn)
                      cmd.ExecuteNonQuery()
      
                  End Using
      
              End If
      
              Using cmd As New Odbc.OdbcCommand("INSERT INTO BOOKS (title) VALUES('The Story of Bill')", cn)
                  cmd.ExecuteNonQuery()
      
              End Using
      
              cn.Close()
      
          End Using
      
          Console.Write("done")
          Console.ReadKey()
      
      End Sub
      

      End Module