Proc Simple use case--VC connecting to Oracle

Source: Internet
Author: User
Tags server port

Operating system: Windows 7

Database version number: Oracle 10g

VS Version number: VS2010

Introduction: There are many ways to connect Oracle, here only proc Shell, explain how to connect Oracle, what's the matter, I hope you tell me to point out, study together.

First, install the corresponding client version number for Oracle 10g.

Note: Do the customer configuration, take this machine as an example: D:\oracle\product\10.2.0\client_2\NETWORK\ADMIN\tnsnames.ora file is

# 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 server IP address; port:oracle server port, default 1521;service_name: Database name.

Second, the establishment of ORACLE.PC file, the contents of the document are:

Oracle.cpp:Defines the entry point for the console application.//#include <stdio.h> #include <stdlib.h> #in Clude <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 Please enter user name:"), gets ((char*) myusername.arr); Myusername.len = (unsigned short) strlen ( (char*) Myusername.arr);p rintf ("\ n Please enter password:"), gets ((char*) mypassword.arr); Mypassword.len = (unsigned short) strlen ((Ch ar*) Mypassword.arr);p rintf ("\ n Please enter the server name:"), 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 ("\ nthe user%s successfully connected to the server On%s. \ n ", Myusername.arr, Myserver.arr); elseprintf ("\n%ld,%s\n", Sqlca.sqlcode, (char *) SQLCA.SQLERRM.SQLERRMC); return 0;}

Third, locate the PROC.exe file under the Oracle installation folder. The native folder is: D:\oracle\product\10.2.0\client_2\BIN, copy the oracle.pc file to some folder, execute cmd command line, CD to this folder, execute Proc.exe oracle.pc Oracle.cpp command, the Oracle.cpp file is generated under the current folder.

Four, start the VS2010, set up an empty control console Oracle project. The following note, do a good vs project configuration. Copy the oracle.cpp into the Oracle folder and add to project.

Then do the configuration:

1. Database include header file path configuration

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvagvpagvpmzy=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

2. Database Lib file folder configuration

3. Database dependent lib file configuration

Delete the previously generated oracle.cpp file, add oracle.cpp to the Oracle project, and compile the link. There may be several errors:

1, the hint does not include "stdafx.h". Solution: Add # include "StdAfx.h" at the beginning of oracle.cpp

2. Hint error lnk2001:unresolved external symbol "void __cdecl sqlcxt (void * *,unsigned int *,struct sqlexd *,struct sqlcxp Const *) "([email protected] @ [emailprotected]@[email protected] @@z) error. Workaround: extern void sqlcxt (void * *, unsigned int *.) struct sqlexd *, const struct SQLCXP *); add "C" after extern to compile

3, some other problems. Be careful to see if the configured include and LIB paths are correct. And the Lib file name is correct.

Vi. execute the generated oracle.exe. For example, the following:





Proc Simple use case--VC connecting to Oracle

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.