當前位置:首頁 » 操作系統 » c連接遠程oracle資料庫

c連接遠程oracle資料庫

發布時間: 2022-02-27 19:06:50

Ⅰ c程序通過什麼連接oracle

一般c語言連接oracle資料庫通過使用oracle提供的OCI介面和PROC編程介面兩種方式。
OCI方式純粹是一些函數介面。
PROC是oracle提供的一種C與ORACLE sql的混合編程。程序(以.pc為後綴)編好之後,使用oracle提供的proc預編譯程序,將pc文件編譯成c文件(這一過程,相當於將SQL轉換為OCI的介面),然後再使用c語言編譯器生成可以執行文件。
OCI方式不容易入門,它擁有大量的介面函數,要很快熟悉它,非常難。但OCI方式的編程效率很高。
porc方式簡單易用。可用於對性能要求不太高的項目。

Ⅱ Oracle遠程如何連接

  1. 首先保證你的 本地Net服務名配置正確

  2. 要保證你的機器到伺服器的網路暢通


Oracle Sql Developer,這個是Oracle自己的開發工具,免費的,基於java

還有
pl/sql developer,這個用的比較多,是32位的,可以在64位機器上使用。
toad for oracle,這個12.1就有64位的了,32位的也可以配置在64位機器上使用。

當然還有很多。

使用InstantClient,PL/SQL Developer連接Oracle(可以在32位機器上使用、也可以在64位機器上使用):
•1. 下載32位Oracle InstantClient,並展開到某目錄,例如C:instantclient-basic-nt-11.2.0.2.0;
•2. 將系統的tnsnames.ora拷貝到該目錄下;
•3. 在PLSQL Developer中設置Oracle_Home和OCI Library:
ToolsPreferencesOracleConnection:
Oracle_Home: C:instantclient-basic-nt-11.2.0.2.0
OCI Library: C:instantclient-basic-nt-11.2.0.2.0oci.dll
•4. 在PLSQL Developer目錄下新建如下bat文件,替換其快捷方式,啟動PLSQL Developer:
@echo off
set path=C:instantclient-basic-nt-11.2.0.2.0
set ORACLE_HOME=C:instantclient-basic-nt-11.2.0.2.0
set TNS_ADMIN=C:instantclient-basic-nt-11.2.0.2.0
set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
start plsqldev.exe

Ⅲ 如何遠程連接oracle資料庫

配置好相關的文件就可以,一般是tnsname.ora文件。
一般oracle10g的文件所在目錄為:C:\oracle\proct\10.2.0\db_1\network\ADMIN
其他版本的可在oracle目錄下搜索tnsname.ora文件名進行修改。

ora =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

其中ora為本地實例名,xxx.xxx.xxx.xxx為遠程IP地址,1521為埠號,orcl為遠程資料庫實例名,按照對方提供的內容進行修改即可。

linux下c++遠程連接oracle資料庫

你說的復合結構應該是結構體吧。若是舉個例子給你看看

/*
* sample2.pc
*
* This program connects to ORACLE, declares and opens a cursor,
* fetches the names, salaries, and commissions of all
* salespeople, displays the results, then closes the cursor.
*/
#include <stdio.h>
#include <sqlca.h>
#define UNAME_LEN 20
#define PWD_LEN 40
/*
* Use the precompiler typedef』ing capability to create
* null-terminated strings for the authentication host
* variables. (This isn』t really necessary--plain char *』s
* does work as well. This is just for illustration.)
*/
typedef char asciiz[PWD_LEN];
EXEC SQL TYPE asciiz IS STRING(PWD_LEN) REFERENCE;
asciiz username;
asciiz password;
struct emp_info
{
asciiz emp_name;
float salary;
float commission;
};
/* Declare function to handle unrecoverable errors. */
void sql_error();
main()
{
struct emp_info *emp_rec_ptr;
/* Allocate memory for emp_info struct. */
if ((emp_rec_ptr =
(struct emp_info *) malloc(sizeof(struct emp_info))) == 0)
{
fprintf(stderr, "Memory allocation error. ");
exit(1);
}
/* Connect to ORACLE. */
strcpy(username, "SCOTT");
strcpy(password, "TIGER");
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--");
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf(" Connected to ORACLE as user: %s ", username);
/* Declare the cursor. All static SQL explicit cursors
* contain SELECT commands. 』salespeople』 is a SQL identifier,
* not a (C) host variable.
*/
EXEC SQL DECLARE salespeople CURSOR FOR
SELECT ENAME, SAL, COMM FROM EMP WHERE JOB LIKE 』SALES%』;
/* Open the cursor. */
EXEC SQL OPEN salespeople;
/* Get ready to print results. */
printf(" The company』s salespeople are-- ");
printf("Salesperson Salary Commission ");
printf("----------- ------ ---------- ");
/* Loop, fetching all salesperson』s statistics.
* Cause the program to break the loop when no more
* data can be retrieved on the cursor.
*/
EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
{
EXEC SQL FETCH salespeople INTO :emp_rec_ptr;
printf("%-11s%9.2f%13.2f ", emp_rec_ptr->emp_name,emp_rec_ptr->salary, emp_rec_ptr->commission);
}
/* Close the cursor. */
EXEC SQL CLOSE salespeople;
printf(" Arrivederci. ");
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}
void sql_error(msg) char *msg;
{
char err_msg[512];
int buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf(" %s ", msg);
/* Call sqlglm() to get the complete text of the
* error message.
*/
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s ", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(1);
}

Ⅳ vs2010中進行C/C++編程,如何連接和使用oracle資料庫

在Windows的控制面板中,查找ODBC數據源,配置一個能夠連接Oracle的數據源,並測試能夠成功連接。然後在VS中連接這個數據源即可。

Ⅵ windows系統下,c如何連接oracle資料庫

首先,這類問題應該問到編程區去,這是軟體喔

########insert.pc############
#include <stdio.h>
EXEC SQL INCLUDE SQLCA;

void insert (char password_[6],char id_[20],int balance_)
{

EXEC SQL BEGIN DECLARE SECTION;
VARCHAR user[20],pass[20],tnsname[20];
char password[6];
char id[20];
int balance;
EXEC SQL END DECLARE SECTION;

strcpy(user.arr,"scott");
user.len=(unsigned short)strlen((char *)user.arr);
strcpy(pass.arr,"tiger");
pass.len=(unsigned short)strlen((char *)pass.arr);
strcpy(tnsname.arr,"demo1");
tnsname.len=(unsigned short)strlen((char *)tnsname.arr);

strcpy(id,id_);
strcpy(password,password_);
balance = balance_;

EXEC SQL CONNECT :user IDENTIFIED BY :pass USING :tnsname;

EXEC SQL insert into bank_bingo values (:id , :password , :balance);

EXEC SQL COMMIT WORK;
EXEC SQL commit work release;

}

#################main.c####################

#include <stdio.h>
extern void insert (char password_[6],char id_[20],int balance_);
int main(int argc , char ** argv){
char id [20] = "10001";
char password[6] = "123";
int balance = 10000;
insert(password , id , balance);
return 0;
}

############################################

Ⅶ 怎麼遠程連接oracle資料庫

第一種情況:

若oracle伺服器裝在本機上,那就不多說了,連接只是用戶名和密碼的問題了。不過要注意環境變數%ORACLE_HOME%/network/admin/是否設置。

第二種情況:

本機未安裝oracle伺服器,也未安裝oracle客戶端。但是安裝了pl sql development、toad sql development、sql navigator等管理資料庫的工具。在虛擬機或者另一台電腦上安裝了oracle伺服器,也就是虛擬機或者另一台電腦此時作為伺服器。

這種情況下,本人以pl sql development遠程連接ORACLE服務端資料庫為例:

1、在安裝oracle伺服器的機器上搜索下列文件:

oci.dll
ocijdbc10.dll
ociw32.dll
orannzsbb10.dll
oraocci10.dll
oraociei10.dll
sqlnet.ora
tnsnames.ora
classes12.jar
ojdbc14.jar
把這些找到的文件復制放到一個文件夾,如 oraclient,將此文件夾復制到客戶端機器上。如放置路徑為 D:oraclient。

2、配置tnsnames.ora,修改其中的資料庫連接串。

oracledata = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.58)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = oracledata) )

其中,oracledata是要連接的服務名;HOST = 192.168.0.58,是伺服器IP地址;PORT = 1521是埠號。

3、添加第一個環境變數,名為TNS_ADMIN,值為tnsnames.ora文件所在路徑(如:D:oraclient,特別是重裝後或其它操作,忘了TNS_ADMIN變數,plsql登陸就會報無法解析指定的連接標識符),這是為了能夠找到上面說的tnsnames.ora。這步是最重要的。

添加第二個環境變數(可有可無):「NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK」,(AMERICAN_AMERICA.US7ASCII 是ASCII編碼類型,其它類型可自己到伺服器看一下或網上查找一下)(本步驟暫時要做對,如果編碼不對,會產生亂碼)。

4、下載並安裝PL SQL Developer配置應用:

打開PL SQL Developer,登入界面點取消,進入後選擇菜單欄 tools->preferences->connection :

Oracle Home=D:oracleclient OCI library=D:oracleclientoci.dll

5、再次打開plsql則會在database中有oracledata 選項輸入用戶名密碼就可以登陸。

第三種情況:

本機未安裝ORACLE伺服器,但是安裝了oracle客戶端,也安裝了pl sql development、toad sql development、sql navigator等管理資料庫的工具。在虛擬機或者另一台電腦上安裝了oracle伺服器,也就是虛擬機或者另一台電腦此時作為伺服器。

這種情況下,本人以pl sql development遠程連接oracle服務端資料庫為例:

1、打開oracle客戶端中的net manager,配置要遠程連接的資料庫名、IP地址等,如果net manager中沒有要遠程連接的資料庫名,則新建即可。

2、其他步驟與第二種情況中的2---5相同。

第四種情況:

本機未安裝oracle伺服器,也未安裝pl sql development、toad sql development、sql navigator等管理資料庫的工具,但是安裝了oracle客戶端。在虛擬機或者另一台電腦上安裝了ORACLE伺服器,也就是虛擬機或者另一台電腦此時作為伺服器。

這種情況下,本人以oracle客戶端中的sqlplus遠程連接oracle服務端資料庫為例:

1、打開oracle客戶端中的net manager,配置要遠程連接的資料庫名、IP地址等,如果net manager中沒有要遠程連接的資料庫名,則新建即可。

2、同第二種情況中的步驟二。

3、同第二種情況中的步驟三。

4、打開sqlplus:

(1)如果用sys用戶登入,則用戶名:sys 密碼:xxxxxx 主機字元串:要連接的資料庫名 as sysdba,登入即可。

(2)如果用其他用戶登入,則用戶名:xxx 密碼:xxxxxx 主機字元串:要連接的資料庫名,登入即可。

注意事項:

1、伺服器端和客戶端防火牆需要關閉;

2、我們經常會遇到***服務無法啟動,那麼需要打開Net Configuration Assistant修復,或者新建***服務。

3、資料庫密碼如果忘了怎麼辦?按照以下方法修改密碼即可:

開始-->運行-->cmd

輸入 :sqlplus /nolog 回車

輸入 :connect / as sysdba 回車

用戶解鎖 : alter user system account unlock 回車

修改密碼:alter user system identified by manager

4、怎樣判斷資料庫是運行在歸檔模式下還是運行在非歸檔模式下?

進入dbastudio,歷程--〉資料庫---〉歸檔查看。

5、另外,如果本機和別的機子均安裝了oracle伺服器端,那麼本機如果要連接別的機子,就必須修改tnsnames.ora.

Ⅷ cmd連接遠程oracle資料庫

您好,提問者:
這樣可以是可以,但是如果那個機器沒有安裝或者配置oracle環境變數就找不到了。
用.bat腳本的時候先檢查一下環境變數是否有這個路徑存在,如果沒有就提示,有就連接。

熱點內容
青椒雲電腦什麼配置 發布:2024-09-22 12:24:50 瀏覽:277
pythongbkunicode 發布:2024-09-22 12:24:06 瀏覽:990
空調壓縮機保險在哪裡 發布:2024-09-22 12:18:01 瀏覽:363
筆記本配置看哪些 發布:2024-09-22 12:06:41 瀏覽:856
魔獸地圖腳本製作 發布:2024-09-22 12:04:48 瀏覽:799
演算法衰減 發布:2024-09-22 11:58:42 瀏覽:49
抖音安卓機客服中心在哪裡 發布:2024-09-22 11:58:40 瀏覽:357
php監控系統 發布:2024-09-22 11:49:58 瀏覽:930
電腦開箱如何看配置 發布:2024-09-22 11:24:44 瀏覽:216
php防止採集 發布:2024-09-22 11:04:42 瀏覽:238