Home All Groups Group Topic Archive Search About

Linking SQL Server to a DBF file

Author
29 Sep 2005 8:23 PM
Zachary Hartnett
I believe I should be able to link to a .dbf file as a
Linked Server through SQL Server.

For instance, in C# code, we can connect with a DBF file
using either ODBC...

---------------------------------------------------------
  System.Data.Odbc.OdbcConnection odbcConnection =
    new System.Data.Odbc.OdbcConnection(
      "MaxBufferSize=2048;" +
      "DSN=dBASE Files;" +
      "PageTimeout=5;" +
      "UID=admin;" +
      "DefaultDir=\\\\teh-web1\\c$\\Inetpub\\wwwroot\\TransnetASP\\WebData;"
+
      "DBQ=\\\\teh-web1\\c$\\Inetpub\\wwwroot\\TransnetASP\\WebData\\buddata;"
+
      "DriverId=533");

  System.Data.Odbc.OdbcCommand odbcCommand =
    new System.Data.Odbc.OdbcCommand(
      "SELECT P1LIB FROM TEOPTDTL", odbcConnection);

  System.Data.Odbc.OdbcDataAdapter odbcAdapter =
    new System.Data.Odbc.OdbcDataAdapter(odbcCommand);

  DataSet odbcDataSet = new DataSet();

  odbcAdapter.Fill(odbcDataSet);
---------------------------------------------------------

....or the Jet driver...

---------------------------------------------------------
  System.Data.OleDb.OleDbConnection oleConnection =
    new System.Data.OleDb.OleDbConnection(
      "Provider=Microsoft.Jet.OLEDB.4.0;" +
      "Data Source=\\\\TEH-Web1\\WebSites\\TransnetASP\\WebData\\buddata;" +
      "Extended Properties=dBASE IV;" +
      "User ID=Admin;" +
      "Password=");

  System.Data.OleDb.OleDbCommand oleCommand =
    new System.Data.OleDb.OleDbCommand(
      "SELECT P1LIB FROM TEOPTDTL", oleConnection);

  System.Data.OleDb.OleDbDataAdapter oleAdapter =
    new System.Data.OleDb.OleDbDataAdapter(oleCommand);

  DataSet oleDataSet = new DataSet();

  oleAdapter.Fill(oleDataSet);
---------------------------------------------------------

When I attempt to create a linked server entry I always
receive an error similar to the following:

  Server: Msg 208, Level 16, State 1, Line 1
  Invalid object name 'Test.TEOPTDTL'.

No tables show up under the tables section in
enterprise manager. I have tried various combinations
through both the wizard and the console to add the
linked server. I have also tried various "select"
statements, such as

  select P1LIB from Test.TEOPTDTL
  select P1LIB from Test.BudData.TEOPTDTL

My most recent non-wizard attempt to link the server was
via the following command.

EXEC sp_addlinkedserver
   @server = 'Test',
   @srvproduct = '',
   @provider = 'MSDASQL',
   @provstr = 'MaxBufferSize=2048;DSN=dBASE
Files;PageTimeout=5;UID=admin;DefaultDir=\\teh-web1\c$\Inetpub\wwwroot\TransnetASP\WebData;DBQ=\\teh-web1\c$\Inetpub\wwwroot\TransnetASP\WebData\buddata;DriverId=533'
GO

Given the choice, I would prefer to use Jet since it has
proven much faster than the ODBC connection. It doesn't
really make much of a difference to me which driver is
used, however. I'm just curious if I am incorrectly linking
the server to the DBF file (based upon the
sp_addlinkedserver command) or if my select syntax
is invalid.

Thanks in advance for any insight!

Author
29 Sep 2005 8:34 PM
oj
EXEC sp_addlinkedserver
    'DBF',
    'Jet 4.0',
    'Microsoft.Jet.OLEDB.4.0',
    '\teh-web1\c$\Inetpub\wwwroot\TransnetASP\WebData',
    NULL,
    'dBase IV'


--
-oj


Show quote
"Zachary Hartnett" <NoSpamPlease@NoSpam.no> wrote in message
news:eR0sKPTxFHA.3856@tk2msftngp13.phx.gbl...
>I believe I should be able to link to a .dbf file as a
> Linked Server through SQL Server.
>
> For instance, in C# code, we can connect with a DBF file
> using either ODBC...
>
> ---------------------------------------------------------
>  System.Data.Odbc.OdbcConnection odbcConnection =
>    new System.Data.Odbc.OdbcConnection(
>      "MaxBufferSize=2048;" +
>      "DSN=dBASE Files;" +
>      "PageTimeout=5;" +
>      "UID=admin;" +
>
> "DefaultDir=\\\\teh-web1\\c$\\Inetpub\\wwwroot\\TransnetASP\\WebData;" +
>
> "DBQ=\\\\teh-web1\\c$\\Inetpub\\wwwroot\\TransnetASP\\WebData\\buddata;" +
>      "DriverId=533");
>
>  System.Data.Odbc.OdbcCommand odbcCommand =
>    new System.Data.Odbc.OdbcCommand(
>      "SELECT P1LIB FROM TEOPTDTL", odbcConnection);
>
>  System.Data.Odbc.OdbcDataAdapter odbcAdapter =
>    new System.Data.Odbc.OdbcDataAdapter(odbcCommand);
>
>  DataSet odbcDataSet = new DataSet();
>
>  odbcAdapter.Fill(odbcDataSet);
> ---------------------------------------------------------
>
> ...or the Jet driver...
>
> ---------------------------------------------------------
>  System.Data.OleDb.OleDbConnection oleConnection =
>    new System.Data.OleDb.OleDbConnection(
>      "Provider=Microsoft.Jet.OLEDB.4.0;" +
>      "Data Source=\\\\TEH-Web1\\WebSites\\TransnetASP\\WebData\\buddata;"
> +
>      "Extended Properties=dBASE IV;" +
>      "User ID=Admin;" +
>      "Password=");
>
>  System.Data.OleDb.OleDbCommand oleCommand =
>    new System.Data.OleDb.OleDbCommand(
>      "SELECT P1LIB FROM TEOPTDTL", oleConnection);
>
>  System.Data.OleDb.OleDbDataAdapter oleAdapter =
>    new System.Data.OleDb.OleDbDataAdapter(oleCommand);
>
>  DataSet oleDataSet = new DataSet();
>
>  oleAdapter.Fill(oleDataSet);
> ---------------------------------------------------------
>
> When I attempt to create a linked server entry I always
> receive an error similar to the following:
>
>  Server: Msg 208, Level 16, State 1, Line 1
>  Invalid object name 'Test.TEOPTDTL'.
>
> No tables show up under the tables section in
> enterprise manager. I have tried various combinations
> through both the wizard and the console to add the
> linked server. I have also tried various "select"
> statements, such as
>
>  select P1LIB from Test.TEOPTDTL
>  select P1LIB from Test.BudData.TEOPTDTL
>
> My most recent non-wizard attempt to link the server was
> via the following command.
>
> EXEC sp_addlinkedserver
>   @server = 'Test',
>   @srvproduct = '',
>   @provider = 'MSDASQL',
>   @provstr = 'MaxBufferSize=2048;DSN=dBASE
> Files;PageTimeout=5;UID=admin;DefaultDir=\\teh-web1\c$\Inetpub\wwwroot\TransnetASP\WebData;DBQ=\\teh-web1\c$\Inetpub\wwwroot\TransnetASP\WebData\buddata;DriverId=533'
> GO
>
> Given the choice, I would prefer to use Jet since it has
> proven much faster than the ODBC connection. It doesn't
> really make much of a difference to me which driver is
> used, however. I'm just curious if I am incorrectly linking
> the server to the DBF file (based upon the
> sp_addlinkedserver command) or if my select syntax
> is invalid.
>
> Thanks in advance for any insight!
>
Author
1 Oct 2005 5:39 AM
Cindy Winegarden
Hi Zachary,

If you can connect to your data using JET via C# then OJ's code should work.

However, there are many flavors of DBF files, and some of them are not
compatible with JET and not compatible with ODBC. All versions of FoxPro
DBFs are compatible with the FoxPro and Visual FoxPro OLE DB data provider,
downloadable from http://msdn.microsoft.com/vfoxpro/downloads/updates .

Here's what works for me using OLE DB:

sp_addlinkedserver 'MyLinkedServer', 'Description', 'VfpOleDb.1',
'C:\MyPath\'
Select * From MyLinkedServer...MyTable


--
Cindy Winegarden  MCSD, Microsoft Visual FoxPro MVP
cindy_winegar***@msn.com  www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden


Show quote
"Zachary Hartnett" <NoSpamPlease@NoSpam.no> wrote in message
news:eR0sKPTxFHA.3856@tk2msftngp13.phx.gbl...
>I believe I should be able to link to a .dbf file as a
> Linked Server through SQL Server. .......
>
> When I attempt to create a linked server entry I always
> receive an error ...

AddThis Social Bookmark Button