PROC簡單的用例--VC串連ORACLE

來源:互聯網
上載者:User

標籤:

作業系統:windows 7

資料庫版本號碼:oracle 10g

VS版本號碼:VS2010

前言:串連ORACLE有許多方法,這裡只PROC外殼,說明如何串連oracle,有事嗎,希望你告訴我指出,一起學習。

一、安裝oracle 10g相應的client版本號碼。

  注意事項:做好客戶配置,以本機為例:D:\oracle\product\10.2.0\client_2\NETWORK\ADMIN\tnsnames.ora檔案為

# tnsnames.ora Network Configuration File: d:\oracle\product\10.2.0\client_2\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

DB_DEMO =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.8.222)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = db_demo)
    )
  )

host:ORACLE服務端IP地址;PORT:ORACLE服務端port號,默覺得1521;SERVICE_NAME:資料庫名稱。

二、建立oracle.pc檔案,檔案內容為:

// oracle.cpp : Defines the entry point for the console application.//#include <stdio.h>#include <stdlib.h>#include <process.h> #include <errno.h> //EXEC SQL INCLUDE SQLCA;#include <sqlca.h>int main(int argc, char* argv[]){EXEC SQL BEGIN DECLARE SECTION;VARCHAR myusername[20], mypassword[20], myserver[20];EXEC SQL END DECLARE SECTION;printf( "\n請輸入使用者名稱:" );gets( (char*)myusername.arr );myusername.len = (unsigned short) strlen( (char*)myusername.arr );printf( "\n請輸入口令:" );gets( (char*)mypassword.arr );mypassword.len = (unsigned short) strlen( (char*)mypassword.arr );printf("\n請輸入伺服器名:");gets( (char*)myserver.arr );myserver.len = (unsigned short) strlen( (char*)myserver.arr );EXEC SQL CONNECT :myusername IDENTIFIED BY :mypassword USING :myserver;if(sqlca.sqlcode < 0 )printf (" \n使用者%s成功地串連到了伺服器%s上。\n" , myusername.arr, myserver.arr); elseprintf("\n%ld,%s\n", sqlca.sqlcode,(char *)sqlca.sqlerrm.sqlerrmc);return 0;}

三、找到ORACLE安裝資料夾下PROC.exe檔案。本機檔案夾為:D:\oracle\product\10.2.0\client_2\BIN,將oracle.pc檔案複製到些檔案夾下,執行cmd命令列,cd到此檔案夾下,執行proc.exe oracle.pc oracle.cpp命令,會在當前檔案夾下產生oracle.cpp檔案。

四、啟動VS2010,建立空控制項台的oracle項目。下面要注意了,做好VS項目配置。將oracle.cpp的拷貝至oracle檔案夾下,加入進project。

然後做的配置:

1、資料庫include標頭檔路徑配置

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVpaGVpMzY=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" >

2、資料庫LIB檔案檔案夾配置

3、資料庫依賴LIB檔案配置

五、刪除之前自己主動產生的oracle.cpp檔案,將oracle.cpp加入進oracle項目,編譯連結。可能會出現下面幾個錯誤:

1、提示未include "stdafx.h"。解決方式:在oracle.cpp開始部位加入#include "stdafx.h"

2、提示 error LNK2001: unresolved external symbol "void __cdecl sqlcxt(void * *,unsigned int *,struct sqlexd *,struct sqlcxp const *)" ([email protected]@[email protected]@[email protected]@@Z)錯誤。解決方式:extern  void sqlcxt (void **, unsigned int *。struct sqlexd *, const struct sqlcxp *);在extern後加上"C"編譯就可以

3、其他一些問題。就細緻查看配置的include、lib路徑是否正確。以及lib檔案名稱是否正確。

六、執行產生的oracle.exe。例如以下:





PROC簡單的用例--VC串連ORACLE

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.