Αναγν. άρθρου: 207595 - Τελευταία αναθεώρηση: Κυριακή, 19 Δεκεμβρίου 2010 - Αναθεώρηση: 2.0

Με τη διαδικασία SQL Server 2000 διανέμονται ερωτήματα με τα αρχεία .dbf FoxPro

Συμβουλή συστήματοςΑυτό το άρθρο ισχύει για διαφορετικό λειτουργικό σύστημα από αυτό που χρησιμοποιείτε. Το περιεχόμενο του άρθρου που ενδέχεται να μην σας αφορά έχει απενεργοποιηθεί.
Ανάπτυξη όλων | Σύμπτυξη όλων

Περίληψη

Αυτό το άρθρο επιδεικνύει τον τρόπο εκτέλεσης του SQL Server κατανεμημένη ερώτημα για την ανάκτηση δεδομένων από FoxPro .dbc και .dbf αρχεία χρησιμοποιώντας το πρόγραμμα οδήγησης VFP ODBC ή την υπηρεσία παροχής VFP OLE DB.

Περισσότερες πληροφορίες

Microsoft SQL Server 2000 παρέχει τη δυνατότητα να εκτελούν ερωτήματα από υπηρεσίες παροχής OLE DB. Αυτό γίνεται χρησιμοποιώντας τις συναρτήσεις OpenQuery ή OpenRowset Transact-SQL ή χρησιμοποιώντας ένα ερώτημα με τετραμερή ονόματα μαζί με ένα συνδεδεμένο διακομιστή όνομα.

Για παράδειγμα:

sp_addlinkedserver 'mylinkedserver', 'product_name', 'myoledbprovider', 'data_source', 'θέση', 'provider_string', 'του καταλόγου'

SELECT * FROM OPENQUERY(mylinkedserver, 'select * from table1')

Πρέπει να χρησιμοποιείτε την υπηρεσία παροχής Microsoft OLE DB για ODBC (MSDASQL) και το πρόγραμμα οδήγησης Visual FoxPro ODBC για να ορίσετε ένα συνδεδεμένο διακομιστή για να εκτελέσετε ερωτήματα κατανεμημένες σε σχέση με τα αρχεία .dbf και να .dbc του FoxPro. Η χρήση του Jet OLEDB Provider FoxPro δεν υποστηρίζεται. Το πρόγραμμα οδήγησης VFP ODBC δεν διαθέτει ασφάλεια νήματος. Επειδή ο SQL Server είναι πολλαπλών νημάτων, το πρόγραμμα οδήγησης VFP ODBC μπορεί να προκαλέσει προβλήματα σε ορισμένες περιστάσεις. Εάν είναι δυνατό, συνιστούμε τη χρήση της υπηρεσίας παροχής VFP OLE DB για σύνδεση με τα δεδομένα του SQL Server.

Το ακόλουθο παράδειγμα κώδικα T SQL επιδεικνύει τον τρόπο ρύθμισης και χρήσης κατανεμημένης ερωτήματα με FoxPro με συναρτήσεις OpenQuery και OpenRowset. Επίσης, επιδεικνύει τον τρόπο ενημέρωσης ενός απομακρυσμένου πίνακα FoxPro από το SQL Server 2000. Μπορείτε να ελέγξετε τον κωδικό αυτό στο SQL Query Analyzer μετά την εγκατάσταση του προγράμματος οδήγησης Visual FoxPro ODBC σε έναν υπολογιστή SQL Server 2000. Θα πρέπει να αλλάξετε τα ονόματα αρχείων προέλευσης δεδομένων και τη διαδρομή προς τα αρχεία FoxPro, ανάλογα με την περίπτωση:
/* OPENROWSET and OPENQUERY examples with VFP via ODBC OLE DB provider */ 

/* These OPENROWSET examples depend on the sample files VFP98\data\Testdata.dbc
Modify your code accordingly for differences in location or DBC name */ 

--====================================================
-- Using DBC file , read and update
--====================================================
-- OPENROWSET DSN-less example

select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data\Testdata.dbc;
SourceType=DBC',
'select * from customer where country != "USA" order by country')
go

select * from  openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data\Testdata.dbc;
SourceType=DBC',
'select * from customer where region="WA"')
go

Update  openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data\Testdata.dbc;
SourceType=DBC',
'select * from customer where region="WA"')
set region = "Seattle" 
go

-- check to verify which rows were updated
select * from  openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data\Testdata.dbc;
SourceType=DBC',
'select * from customer where region="Seattle"') 
go

-- OPENROWSET DSN example
/* Note the DSN Example might fail if SQL Server is configured to use a local account.*/ 
select * from openrowset('MSDASQL',
'DSN=Visual FoxPro Database;
SourceDB=e:\VFP98\data\Testdata.dbc;
SourceType=DBC',
'select * from customer where country != "USA" order by country'
go

/* sp_addlinkedserver examples */ 
-- sp_addlinkedserver example with DSN

/* You will need to make a DSN and point it to the Testdata database. 
Modify your code accordingly for differences in location or DBC name */ 

/* Note this Example may fail if SQL Server is configured to use a local account.*/ 
sp_addlinkedserver 'VFP Testdata Database With DSN', 
    '', 
    'MSDASQL',
    'VFP System DSN'
go

sp_addlinkedsrvlogin 'VFP Testdata Database With DSN', FALSE, NULL, NULL, NULL
go 

SELECT *
FROM OPENQUERY([VFP Testdata Database With DSN], 'select * from customer where region = "Seattle"') 
go

-- Update using OpenQuery
Update OPENQUERY([VFP Testdata Database With DSN], 'select * from customer where region="WA"') 
set region = "Seattle" 
go

/* SP_addlinkedserver example with DSN-less connection */ 

/* This example also depends on the sample files Testdata.dbc
Modify your code accordingly for differences in location or DBC name */ 

sp_addlinkedserver 'VFP Testdata Database With No DSN', 
    '', 
    'MSDASQL',
    NULL,
    NULL,
'Driver={Microsoft Visual FoxPro Driver};UID=;PWD=;SourceDB=e:\VFP98\data\Testdata.dbc;SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;'
go

sp_addlinkedsrvlogin 'VFP Testdata Database With No DSN', FALSE, NULL, NULL, NULL
go

SELECT *
FROM OPENQUERY([VFP Testdata Database With No DSN], 'select * from customer where country != "USA" order by country') 
go

--====================================================
-- Using VFP 6.0 driver, read and update data from VFP sample dbf files
--====================================================

-- OPENROWSET DSN-less example

select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data;
SourceType=DBF',
'select * from customer where country != "USA" order by country')
go

-- perform UPDATE

Update openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data;
SourceType=DBF',
'select * from customer where region="Seattle"')
set region = "WA"
go

-- verify update

select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:\VFP98\data;
SourceType=DBF',
'select * from customer where region = "WA"')
go<BR/>

-- OPENROWSET DSN example
-- DSN points to the folder where .dbf files are.
/* Note this Example may fail if SQL Server is configured to use a local account.*/ 
select * from openrowset('MSDASQL',
'DSN=Visual FoxPro Tables;			
SourceDB=e:\VFP98\data;
SourceType=DBF',
'select * from customer where country != "USA" order by country') 
go"?
-- SQL Server's QUOTED_IDENTIFIER has to be set to OFF.

 

SET QUOTED_IDENTIFIER OFF

 

            -- OPENROWSET DSN-less example

            

            select * from openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data\Testdata.dbc;

            SourceType=DBC',

            'select * from customer where country = "USA" order by city')

            go

            

            select * from  openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data\Testdata.dbc;

            SourceType=DBC',

            'select * from customer where region="WA"')

            go

            

            Update  openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data\Testdata.dbc;

            SourceType=DBC',

            'select * from customer where city = "Seattle"')

            set region = "WW" 

            go

            

            -- check to verify which rows were updated

            select * from  openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data\Testdata.dbc;

            SourceType=DBC',

            'select * from customer where region="WW"') 

            go

            

            -- OPENROWSET DSN example

            /* Note the DSN Example might fail if SQL Server is configured to use a local account.*/ 

            select * from openrowset('MSDASQL',

            'DSN=Visual FoxPro Database;

            SourceDB=e:\VFP90\samples\data\Testdata.dbc;

            SourceType=DBC',

            'select * from customer where country = "USA" order by city')

            go

            

            /* sp_addlinkedserver examples */ 

            -- sp_addlinkedserver example with DSN

            

            /* You will need to make a DSN and point it to the Testdata database. 

            Modify your code accordingly for differences in location or DBC name */ 

            

            /* Note this Example may fail if SQL Server is configured to use a local account.*/ 

            sp_addlinkedserver 'VFP Testdata Database With DSN', 

                '', 

                'MSDASQL',

                'VFP System DSN'

            go

            

            sp_addlinkedsrvlogin 'VFP Testdata Database With DSN', FALSE, NULL, NULL, NULL

            go 

            

            SELECT *

            FROM OPENQUERY([VFP Testdata Database With DSN], 'select * from customer where city = "Seattle" ') 

            go

            

            -- We will set the region back to "WA" if it currently is "WW".

            -- Update using OpenQuery

            Update OPENQUERY([VFP Testdata Database With DSN], 'select * from customer where city = "Seattle" ') 

            set region = "WA" 

            go

            

            -- Make sure that the region got updated.

            SELECT *

            FROM OPENQUERY([VFP Testdata Database With DSN], 'select * from customer where city = "Seattle" ') 

            go

            

            /* SP_addlinkedserver example with DSN-less connection */ 

            

            /* This example also depends on the sample files Testdata.dbc

            Modify your code accordingly for differences in location or DBC name */ 

            

            sp_addlinkedserver 'VFP Testdata Database With No DSN', 

                '', 

                'MSDASQL',

                NULL,

                NULL,

            'Driver={Microsoft Visual FoxPro Driver};UID=;PWD=;SourceDB=e:\VFP90\samples\data\Testdata.dbc;SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;'

            go

            

            sp_addlinkedsrvlogin 'VFP Testdata Database With No DSN', FALSE, NULL, NULL, NULL

            go

            

            SELECT *

            FROM OPENQUERY([VFP Testdata Database With No DSN], 'select * from customer where country = "USA" order by city') 

            go

            

            --====================================================

            -- Using VFP 6.0 driver, read and update data from VFP sample dbf files

            --====================================================

            

            -- OPENROWSET DSN-less example

            

            select * from openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data;

            SourceType=DBF',

            'select * from customer where country != "USA" order by country')

            go

            

            -- perform UPDATE

            

            Update openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data;

            SourceType=DBF',

            'select * from customer where city = "Seattle"')

            set region = "WW" 

            go

            

            -- verify update

            

            select * from openrowset('MSDASQL',

            'Driver=Microsoft Visual FoxPro Driver;

            SourceDB=e:\VFP90\samples\data;

            SourceType=DBF',

            'select * from customer where region = "WW"')

            go

            

            -- OPENROWSET DSN example

            -- DSN points to the folder where .dbf files are.

            /* Note this Example may fail if SQL Server is configured to use a local account.*/ 

            select * from openrowset('MSDASQL',

            'DSN=Visual FoxPro Tables;                              

            SourceDB=e:\VFP90\samples\data;

            SourceType=DBF',

            'select * from customer where country != "USA" order by country') 

            go

Μπορείτε επίσης να χρησιμοποιήσετε το Visual FoxPro OLE DB Provider για να δημιουργήσετε ένα ερώτημα κατανεμημένες. Αυτή είναι η προτιμώμενη τεχνολογία χρήσης. Παρακαλώ Σημειώστε ότι ενώ αυτός ο κώδικας εμφανίζει τον τρόπο ενημέρωσης και διαγραφής δεδομένων, προσθήκη, ενημέρωση (επεξεργασία) και τη διαγραφή δεδομένων σε κατανεμημένες ερώτημα χρησιμοποιώντας την υπηρεσία παροχής OLE DB δεν υποστηρίζεται.

Το ακόλουθο παράδειγμα κώδικα T SQL επιδεικνύει τον τρόπο ρύθμισης και χρήσης κατανεμημένης ερωτήματος με FoxPro με συναρτήσεις OpenQuery και OpenRowset. Μπορείτε να ελέγξετε τον κωδικό αυτό σε SQL Query Analyzer μετά την εγκατάσταση του Visual FoxPro OLE DB Provider σε έναν υπολογιστή SQL Server 2000. Θα πρέπει να αλλάξετε τα ονόματα αρχείων προέλευσης δεδομένων και τη διαδρομή προς τα αρχεία FoxPro, ανάλογα με την περίπτωση:
 '/* These OPENROWSET examples depend on the sample files VFP98\data\Testdata.dbc

'Modify your code accordingly for differences in location or DBC name */

 

--*====================================================

--* Using the DBC file, reading and updating data.

--*====================================================

--* A couple of OPENROWSET queries.

select * from openrowset('VFPOLEDB',

'e:\vfp7junk\Testdata.dbc';'Exclusive=No';'Data Source=DBC',

'select * from customer where country != "USA" order by country')

go

 

Select * from openrowset('VFPOLEDB',

'e:\vfp7junk\Testdata.dbc';'Exclusive=No';'Data Source=DBC',

'select * from customer where region="WA"')

go

 

--* Need to use an error trapping routine with the UPDATE and DELETE functions:

select * from

 openrowset('VFPOLEDB',

   'E:\VFP7Junk\Testdata.DBC';'Exclusive=No';'Data Source=DBC',

   'Update Customer Set city = "SEATTLE" where region = "WA" ') 

go

declare @upderror int

select @upderror = @@error

print ''

if @upderror != 7357 and @upderror != 0

            print  'Update failed with error '+convert(varchar(5),@upderror)

else

            print 'Ignore the error above, the Update succeeded'

go

 

 

-- check to verify which rows were updated

select * from  openrowset('VFPOLEDB',

'E:\VFP7junk\Testdata.DBC';'Exclusive=No';'Data Source=DBC',

'select * from customer where region = "WA"')

go

 

--* Change the City field back to "Seattle".

 

select * from

 openrowset('VFPOLEDB',

   'E:\VFP7Junk\Testdata.DBC';'Exclusive=No';'Data Source=DBC',

   'Update Customer Set city = "Seattle" where region = "WA" ') 

go

declare @upderror int

select @upderror = @@error

print ''

if @upderror != 7357 and @upderror != 0

            print  'Update failed with error '+convert(varchar(5),@upderror)

else

            print 'Ignore the error above, the Update succeeded'

go

 

--* The DELETE fucntion also causes an error, but the DELETE works.

select * from

 openrowset('VFPOLEDB',

   'E:\VFP7Junk\Testdata.DBC';'Exclusive=No';'Data Source=DBC',

   'Delete from Customer where country = "Spain" ') 

go

declare @delerror int

select @delerror = @@error

print ''

if @delerror != 7357 and @delerror != 0

            print  'Delete failed with error '+convert(varchar(5),@delerror)

else

            print 'Ignore the error above, the Delete succeeded'

go

 

--* Check to see that the records are deleted.

Select * from openrowset('VFPOLEDB',

'e:\vfp7junk\Testdata.dbc';'Exclusive=No';'Data Source=DBC',

'select * from customer where country = "Spain"')

go

 

 

--* Here are some examples using the VFP OLE DB Provider to create Linked Servers.

--* Using sp_addlinkedserver to create the Linked Server.

sp_addlinkedserver @server='VFP_Linked_Server',

@srvproduct='Microsoft Visual FoxPro OLE DB Provider', 

@provider='VFPOLEDB',

@datasrc = 'E:\vfp7junk'

go

 

SELECT *

FROM OPENQUERY([VFP_Linked_Server], 'select * from customer where city = "Seattle"')

go

 

 

-- The Update command will update the table with the OPENQUERY function when using the 

-- linked server, but the same error 7357 error will occur.

select * from

 OPENQUERY([VFP_Linked_Server],

   'Update Customer Set city = "SEATTLE" where region = "WA" ') 

go

declare @upderror int

select @upderror = @@error

print ''

if @upderror != 7357 and @upderror != 0

            print  'Update failed with error '+convert(varchar(5),@upderror)

else

            print 'Ignore the error above, the Update succeeded'

go

 

 

-- Check and see if the City field is all uppercase with "SEATTLE".

SELECT *

FROM OPENQUERY([VFP_Linked_Server], 'select * from customer where region = "WA"')

go

 

--* Let's check for how many records have the word "London" in the City field.

SELECT *

FROM OPENQUERY([VFP_Linked_Server], 'select * from customer where city = "London"')

go

 

-- We can also use the Delete command to remove records with the OPENQUERY function when using the 

-- linked server, but the same error 7357 error will occur.

select * from

 OPENQUERY([VFP_Linked_Server],

   'Delete from Customer where city = "London"') 

go

declare @delerror int

select @delerror = @@error

print ''

if @delerror != 7357 and @delerror != 0

            print  'Delete failed with error '+convert(varchar(5),@delerror)

else

            print 'Ignore the error above, the Delete succeeded'

go

 

 

/* SP_addlinkedserver example with DSN-less connection */

 

/* This example also depends on the sample files Testdata.dbc

Modify your code accordingly for differences in location or DBC name */

 

sp_addlinkedserver 'VFP Testdata Database With No DSN',

    '',

    'MSDASQL',

    NULL,

    NULL,

'Driver={Microsoft Visual FoxPro Driver};UID=;PWD=;SourceDB=e:\VFP8junk\Testdata.dbc;SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;'

go

 

 

SELECT *

FROM OPENQUERY([VFP Testdata Database With No DSN], 'select * from customer where country = "USA" order by country')

go

Αναφορές

Για περισσότερες λεπτομέρειες σχετικά με τη δημιουργία και χρήση κατανεμημένων ερωτήματα, Ρίξτε μια ματιά sp_addlinkedserver, OpenQuery, OpenRowset και σχετικά θέματα σε SQL 7.0 Books Online.

Για να μάθετε περισσότερα σχετικά με το FoxPro, καθώς και τα αρχεία .dbf και .dbc, ανατρέξτε στην τεκμηρίωση προϊόντος του FoxPro.

Οι πληροφορίες σε αυτό το άρθρο ισχύουν για:
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • Microsoft Visual FoxPro 7.0 Professional Edition
  • Microsoft Visual FoxPro 8.0 Professional Edition
  • Microsoft Visual FoxPro 9.0 Professional Edition
  • Microsoft SQL Server 2000 Standard Edition
Λέξεις-κλειδιά: 
kbdatabase kbhowto kbmt KB207595 KbMtel
Μηχανικά μεταφρασμένοΜηχανικά μεταφρασμένο
ΣΗΜΑΝΤΙΚΟ: Αυτό το άρθρο είναι προϊόν λογισμικού μηχανικής μετάφρασης της Microsoft και όχι ανθρώπινης μετάφρασης. Η Microsoft σάς προσφέρει άρθρα που είναι προϊόντα ανθρώπινης αλλά και μηχανικής μετάφρασης έτσι ώστε να έχετε πρόσβαση σε όλα τα άρθρα της Γνωσιακής Βάσης μας στη δική σας γλώσσα. Ωστόσο, ένα άρθρο που έχει προκύψει από μηχανική μετάφραση δεν είναι πάντα άριστης ποιότητας. Ενδέχεται να περιέχει λεξιλογικά, συντακτικά ή γραμματικά λάθη, όπως ακριβώς τα λάθη που θα έκανε ένας μη φυσικός ομιλητής επιχειρώντας να μιλήσει τη γλώσσα σας. Η Microsoft δεν φέρει καμία ευθύνη για τυχόν ανακρίβειες, σφάλματα ή ζημίες που προκύψουν λόγω τυχόν παρερμηνειών στη μετάφραση του περιεχομένου ή χρήσης του από τους πελάτες της. Επίσης, η Microsoft πραγματοποιεί συχνά ενημερώσεις στο λογισμικό μηχανικής μετάφρασης.
Η αγγλική έκδοση αυτού του άρθρου είναι η ακόλουθη:207595  (http://support.microsoft.com/kb/207595/en-us/ )