Oracle uses ODBC connection configuration

Source: Internet
Author: User
Tags dsn odbc connection

This configuration is done under Windows 7 32, and the program has passed the test (test with VBS)

1. File download

--------------------------------------------------------------------------

Http://www.oracle.com/technetwork/topics/winsoft-085727.html

You need to download two files Instantclient-basic-nt-12.1.0.2.0.zip "http://download.oracle.com/otn/nt/instantclient/121020/ Instantclient-basic-nt-12.1.0.2.0.zip "

Instantclient-odbc-nt-12.1.0.2.0.zip "http://download.oracle.com/otn/nt/instantclient/121020/ Instantclient-odbc-nt-12.1.0.2.0.zip "

To the official website to download the user name: * * * Password: * * *

Unzip the two compressed packages.

Copy all files and folders in "Instantclient-odbc-nt-12.1.0.2.0.zip" to the files extracted by "Instantclient-basic-nt-12.1.0.2.0.zip"

Suppose you put the files in the "Xxx\instantclient_12_1" folder.

--------------------------------------------------------------------------

2. Installing the Client

-------------------------------------------------------------------------------------------

Open the Instantclient_12_1 folder to find Cmd.exe (if not found and copied under System32) right-click "cmd.exe" file to run as administrator.

Enter "Odbc_install.exe" and click Enter to run, "Oracle ODBC Driver is installed successfully" If successful installation occurs

-----------------------------------------------------------------------------------------

3. What the environment variables need to configure

Right-click Computer--Properties--Advanced system settings--advanced--environment variables--System variables

-----------------------------------------------------------

Oracle_home Xxx\instantclient_12_1

Path Add Xxx\instantclient_12_1

Tns_admin Xxx\instantclient_12_1\network\admin

------------------------------------------------------------

Where the contents of the Tnsnames.ora file in the Xxx\instantclient_12_1\network\admin folder need to be modified to "host=192.168.19.176" in "TESTDB" If you do not have tnsnames.ora files, you need to build your own

"SERVICE_NAME=ORCL" ORCL is SID

4.odbc What you need to configure--control Panel--Administration tools--data source (ODBC)--User dsn--> add

---------------------------------------------------------------

Click "Oracle in Instantclient_12_1" to finish filling in the Oracle ODBC Driver Configuration Dialog

=================================================================

The Data Source name takes a random name like: "BBB"

Description Connection Description: "Xxxxxxxxx"

The TNS Service name is one of two ways to click on the drop-down Tnsnames.ora configuration name such as "TESTDB"

Another way to fill in the IP address + port number +sid such as: "192.168.19.176:1521/ORCL"

UserID access to the database user name

======================================================================

Click on the Test popup "Oracle ODBC Driver Connect" dialog to fill in the password click "OK" if the connection is successful prompt "Connection successful"

The ODBC configuration is now successful

---------------------------------------------------------------

Test
----------------------------------------------------------------------------------

Version BvS
The following is a VBS test program that copies the following files to the extension ". vbs" Double-click the document to test
where "Database=sys" indicates the name of the database to be accessed is the SYS
Find the number of rows in the "audit_actions" table and display them

' ******************************************* ' from the beginning I copied ****************************************

DimObjconnection'Connection object InstanceDimobjRecordSet'Recordset object InstanceDimObjcommand'Command object InstanceDimstrConnectionString'Connection StringSubconnectdatabase ()SetObjconnection =CreateObject("ADODB. CONNECTION")'1-Create an instance of the Connection objectstrConnectionString ="Dsn=bbb;uid=bips48;pwd=m123;database=sys"                                '2-Establish connection stringObjconnection.open strconnectionstringSetobjRecordSet =CreateObject("ADODB. RECORDSET")'4-Build a Recordset object instance    SetObjcommand =CreateObject("Adodb.command")'5-Creating a Command object instanceobjCommand.ActiveConnection =objconnection Objcommand.commandtext="Select COUNT (*) from Audit_actions"objrecordset.cursorlocation=3Objrecordset.open objcommand'6-Execute SQL statement to save the result in the Recordset object instanceIntarraylength= Objrecordset.recordcount'The number of rows in the query result as the length of the array    MsgBoxIntarraylengthIfIntarraylength >0  Then        Do  while  notObjrecordset.eof'assigning the column values of a database query to an array          MsgBoxobjRecordSet ("COUNT (*)") Objrecordset.movenextLoop         End If End SubConnectdatabase

' *************************************** ' Copy to my end *********************************

C # Edition

        Static voidMain (string[] args)            {Console.WriteLine (DateTime.Now); System.Data.Odbc.OdbcConnectionStringBuilder Connbuilder=NewSystem.Data.Odbc.OdbcConnectionStringBuilder (); Connbuilder.dsn="BBB"; Connbuilder.add ("UID","bips48"); Connbuilder.add ("pwd","m123"); Connbuilder.add ("Database","SYS"); stringSSS =connbuilder.tostring ();            Console.WriteLine (Connbuilder.tostring ()); System.Data.Odbc.OdbcConnection Conn=NewSystem.Data.Odbc.OdbcConnection (connbuilder.tostring ()); Try{Conn.                Open (); System.Data.Odbc.OdbcCommand Comm=NewSystem.Data.Odbc.OdbcCommand ("Select COUNT (*) from Audit_actions", conn); varReader =Comm.                ExecuteReader ();  while(reader. Read ()) {Console.WriteLine (reader[0].                ToString ()); } Console.WriteLine ("Connection Successful! "); }            Catch(Exception e) {Console.WriteLine (e); }            finally{Conn.            Close ();        } console.read (); }

----------------------------------------------------------------------------------

Oracle uses ODBC connection configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.