연결된 서버로 SQL Server Visual FoxPro 데이터베이스 추가

이 문서에서는 Visual FoxPro에서 연결된 서버로 Visual FoxPro 데이터 원본을 프로그래밍 방식으로 추가하고 쿼리하는 방법을 소개합니다.

원래 제품 버전: Visual FoxPro
원래 KB 번호: 199131

요약

SQL Server 7.0 및 SQL Server 2000을 사용하면 외부 데이터 원본을 연결된 서버로 추가합니다. 이 기능은 OLE DB 데이터 원본에 대해 다른 유형의 쿼리를 배포할 수 있는 액세스를 제공합니다. 이 문서에서는 Visual FoxPro에서 연결된 서버로 Visual FoxPro 데이터 원본을 프로그래밍 방식으로 추가하고 쿼리하는 방법을 보여 줍니다.

추가 정보

sp_addlinkedserver는 SQL Server 7.0 및 SQL Server 2000에 도입된 새로운 저장 프로시저입니다. sp_addlinkedserver 는 OLE DB 데이터 원본에 대해 다른 유형의 쿼리를 배포할 수 있는 연결된 서버를 만듭니다.

Transact - SQL에서 연결된 서버를 추가하는 구문은 다음과 같습니다.

 sp_addlinkedserver [@server =] 'server',
 [@srvproduct =] 'product_name',
 [@provider =] 'provider_name',
 [@datasrc =] 'data_source',
 [@location =] 'location',
 [@provstr =] 'provider_string',
 [@catalog =] 'catalog'[@server =] 'server' Is the name of the linked server to
 create with sp_addlinkedserver.

[@srvproduct =] 'product_name' Is the product name of the OLE DB data
 source to add as a linked server.

[@provider =] 'provider_name' Is the unique provider identifier of the
 OLE DB provider corresponding to the
 data source.

[@datasrc =] 'data_source' Is the name of the data source, as
 interpreted by the OLE DB provider.

[@location =] 'location' Is the location of or path to the
 database as interpreted by the OLE DB
 provider.

[@provstr =] 'provider_string' Is the OLE DB provider-specific.

[@catalog =] 'catalog' Is the catalog to be used when making a
 connection to the OLE DB provider.

다음 코드 조각은 SAMPLES\DATA 디렉터리의 Visual FoxPro 데이터베이스 Testdata.DBC 를 연결된 서버로 SQL Server 추가합니다. 이 코드 조각은 Visual FoxPro 및 SQL Server 동일한 컴퓨터에서 실행되고 있다고 가정합니다.

참고

사용자 이름에는 데이터베이스에서 이러한 작업을 수행할 수 있는 권한이 있어야 합니다.

 Source_Path=IIF(VAL(SUBSTR(VERSION(),15,2))=6,HOME(2),HOME()+"SAMPLES\")
 Connect_String='DRIVER={SQL Server};' + ;
 'SERVER=MY_SERVER;DATABASE=PUBS;UID=UserName;PWD=StrongPassword'
 gnConnHandle=SQLSTRINGCONN(Connect_String)
 IF gnConnHandle > 0
 * Create a command string to pass to SQL Server via SQLExec
 SQLCommand="sp_addlinkedserver 'VFP','','MSDASQL',NULL,NULL,"+ ;
 "'DRIVER={Microsoft Visual FoxPro Driver};" + ;
 "SourceDB="+Source_Path+"DATA\TESTDATA.DBC;SourceType=DBC;NULL'"* CREATE the LINKED Server"
 Create_Linked_Server=SQLExec(gnConnHandle,SQLCommand)
 IF Create_Linked_Server > 0
 * The linked server was successfully created
 * Run the query
 =RunQuery()
 ELSE
 * The Linked Server either already exists or the command failed.
 * Test for existence of linked server with aerror()
 =AERROR(s_failed)
 IF "VFP' ALREADY EXISTS."$UPPER(s_failed[1,2])
 * The linked server exists, so run the query
 =RunQuery()
 ELSE
 * The linked server doesn't exist, so display a message
 =MESSAGEBOX(s_failed[1,2],32,'Failed')
 ENDIF
 ENDIF
 =SQLDISCONN(gnConnHandle)
 ENDIF

PROCEDURE RunQuery
 SQLCommand="SELECT * FROM OPENQUERY(VFP,'SELECT * FROM CUSTOMER')"
 QRYVal=SQLExec(gnConnHandle,SQLCommand,'SQLRESULTS')
 IF QRYVal > 0
 SELECT SQLResults
 BROW
 ELSE
 =AERROR(L_Server)
 =MESSAGEBOX(L_Server[1,2],32,'Query Failed')
 ENDIF
 RETURN

코드 조각을 실행한 후 SQL Server Enterprise 관리자를 열고 연결된 서버 노드를 확장합니다. VFP라는 연결된 서버가 추가되었습니다.

참조

에 대한 sp_addlinkedserver자세한 내용은 Transact - SQL 참조 도움말 파일에서 을 검색 sp_addlinkedserver 합니다.