关于ODBC连接Oracle数据库

关于ODBC连接Oracle数据库
假设数据库机器名:VENN,地址:192.168.1.102 用户名:SCOTT,密码:TIGER
获得默认连接字符串:
_T(DRIVER={ORACLE ODBC DRIVER};
SERVER=192.168.1.102;databasename=NORA9;UID=SCOTT;PWD=TIGER;);

Oracle数据库连接的这种写法是不正确的。
首先客户端的机器需要安装Oracle客户端,然后在控制面板中建立数据源的就是NORA9,服务器IP地址是在Oracle客户端连接时使用的,不需要写到程序中。
Oracle数据库连接字符串的写法: _T("ODBC;DSN=NORA9;UID=Scott;PWD=tiger");
---------------------------------
要安装oracle客户端,然后修改 oracle/ora81/NETWORK/ADMIN/tnsnames.ora
加入 MYDSN= (DESCRIPTION =NORA8 (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.2.253;)(PORT = 这里填你的端口)) ) (CONNECT_DATA = (SID=Scott) ) )
然后在控制面板-〉管理工具->数据源中建立数据源
建议用CDatabase database;
 database.Open(("ODBC;DSN=NORA8;UID=Scott;PWD=tiger");
CMyDataApp2Set m_set; m_set.pDatabase=&database; m_set.Open();
这样重用database,你同时打开几个set,在Oracle中只占用一个进程。
如果每次m_set去调用GetDefaultConnect(),建立一个新的连接,数据库中就会多出一个进程,而且速度也比较慢。
 --------------------------------- ---------------------------------
ODBC DSNLess Connections:
1) MS Access ODBC DSNless connection Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\dbname.mdb;Uid=Admin;Pwd=pass;
 
2) dBase ODBC DSNless connection Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\somepath\dbname.dbf;

3) Oracle ODBC DSNless connection Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=admin;Pwd=pass;

4) MS SQL Server DSNless connection Driver={SQL Server};Server=servername;Database=dbname;Uid=sa;Pwd=pass;

5) MS Text Driver DSNless connection Driver={Microsoft Text Driver (*.txt; .csv)};Dbq=c:\somepath\;Extensions=asc,csv,tab,txt;Persist Security Info=False;

6) Visual Foxpro DSNless connection Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=c:\somepath\dbname.dbc;Exclusive=No;

7) MySQL DSNless connection driver={mysql};

database=yourdatabase;server=yourserver;uid=username;pwd=password;option=16386;
OLE DB Connections:
1) MS Access OLE DB connection Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\somepath\dbname.mdb;User Id=admin;Password=pass;

2) Oracle OLE DB connection Provider=OraOLEDB.Oracle;Data Source=dbname;User Id=admin;Password=pass;

3) MS SQL Server OLE DB connection Provider=SQLOLEDB;Data Source=machineName;Initial Catalog=dbname;User ID=sa;Password=pass;

4) MS SQL Server OLE DB connection using an IP address Provider=SQLOLEDB; Data Source=xx.xx.xx.xx,1433; Network Library=DBMSSOCN; Initial Catalog=dbname;User ID=sa;Password=pass;

5) MS Text Driver OLE DB connection "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\yourpath;Extended Properties='text;FMT=Delimited'" --------------------------------
posted @ 2007-12-29 15:38  shelvenn's blog  阅读(2975)  评论(0编辑  收藏  举报