Bu makalede, SQL Server dağıtılmış sorguda VFP ODBC sürücüsü veya VFP OLE DB sağlayıcı kullanarak FoxPro .dbc ve .dbf dosyaları veri almak için nasıl gösterilmektedir.
Microsoft SQL Server 2000, OLE DB sağlayıcıları sorgular gerçekleştirme olanağı sağlar. SorguAç veya OpenRowset Transact-SQL işlevleri veya sorguda bir bağlı sunucu adı da dahil olmak üzere four-part adları kullanarak yapılır.
SELECT * FROM OPENQUERY(mylinkedserver, 'select * from table1')
FoxPro .dbc ve .dbf dosyaları dağıtılmış sorgular gerçekleştirmek için bağlı bir sunucu ayarlamak için ODBC (MSDASQL) için Microsoft OLE DB sağlayıcısı ve Visual FoxPro ODBC sürücüsü kullanmalısınız. Jet OLEDB Sağlayıcısı ile FoxPro kullanarak desteklenmiyor. VFP ODBC sürücüsü, iş parçacığı güvenli değil. VFP ODBC sürücüsü, SQL Server, çok iş parçacıklı olduğundan, bazı koşullarda ile ilgili sorunlara neden olabilir. Mümkünse, SQL Server verisine bağlanmak için VFP OLE DB Provider'ı kullanmanızı öneririz.
T-SQL aşağıdaki kod örneği, nasıl kurulacağını ve dağıtılmış sorgular SorguAç ve OpenRowset işlevleriyle FoxPro gösterir. Ayrıca, nasıl yapılır: SQL Server 2000'den uzak FoxPro tablosunu güncelleştirme gösterir. Bir SQL Server 2000 makine üzerinde Visual FoxPro ODBC sürücüsü yükledikten sonra bu kodu, SQL Query Analyzer'da sınayabilirsiniz. Veri kaynağı adları'ı değiştirmeniz gerekir ve yol FoxPro için uygun şekilde dosyaları:
/* 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 sağlayıcı bir dağıtık sorgu oluşturmak için de kullanabilirsiniz. Bu, kullanılacak tercih edilen teknolojisidir. Lütfen bu kodu, veri ekleme, (düzenleme), güncelleştirme, silme ve güncelleştirmek gösterilmiştir ve OLE DB sağlayıcı kullanarak dağıtılmış bir sorgudaki veriyi silme desteklenip desteklenmediği dikkat edin.
Aşağıdaki örnek T-SQL kodu ayarlanıp dağıtık sorgu ile FoxPro SorguAç ve OpenRowset işlevlerinin ile gösterilmiştir. Bir SQL Server 2000 makine üzerinde Visual FoxPro OLE DB sağlayıcı yükledikten sonra bu kodu, SQL Query Analyzer'da sınayabilirsiniz. Veri kaynağı adları'ı değiştirmeniz gerekir ve yol FoxPro için uygun şekilde dosyaları:
'/* 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
Ayarlama ve dağıtılmış sorgular kullanma hakkında daha fazla bilgi için SQL 7.0 Çevrimiçi Kitapları'de sp_addlinkedserver SorguAç, OpenRowset ve ilgili konulara bir göz atın.
FoxPro ve .dbf ve .dbc dosyaları hakkında daha fazla bilgi için <a0></a0>, FoxPro ürün belgelerine bakın.
ÖNEMLİ: Bu makale, bir kişi tarafından çevrilmek yerine, Microsoft makine-çevirisi yazılımı ile çevrilmiştir. Microsoft size hem kişiler tarafından çevrilmiş, hem de makine-çevrisi ile çevrilmiş makaleler sunar. Böylelikle, bilgi bankamızdaki tüm makalelere, kendi dilinizde ulaşmış olursunuz. Bununla birlikte, makine tarafından çevrilmiş makaleler mükemmel değildir. Bir yabancının sizin dilinizde konuşurken yapabileceği hatalar gibi, makale; kelime dağarcığı, söz dizim kuralları veya dil bilgisi açısından yanlışlar içerebilir. Microsoft, içeriğin yanlış çevrimi veya onun müşteri tarafından kullanımından doğan; kusur, hata veya zarardan sorumlu değildir. Microsoft ayrıca makine çevirisi yazılımını sıkça güncellemektedir.
Makalenin İngilizcesi aşağıdaki gibidir:207595
(http://support.microsoft.com/kb/207595/en-us/
)
Bu makaleyi kullanmak için ne kadar kişisel çaba harcadınız?
Çok az
Az
Orta
Fazla
Çok fazla
Bu bilgiyi geliştirmemiz için nedenleri ve bu konuda neler yapabileceğimizi paylaşın
Teşekkürler! Görüşleriniz, destek içeriğimizi geliştirmemize yardımcı olmak için kullanılmaktadır. Diğer yardım seçenekleri için, lütfen Yardım ve Destek Giriş Sayfasını ziyaret edin.