Go Proc Simple use case--VC connecting Oracle

Source: Internet
Author: User

Go Proc Simple use case--VC connecting Oracle

Operating system: Windows 7

Database version: Oracle 10g

VS Version: VS2010

Preface: There are many ways to connect Oracle, here only proc as an example, explain how to connect Oracle, there is something wrong, I hope you crossing point out, learn to go together.

One, install the client version of 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 service port number, default is 1521;service_name: Database name.

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

[CPP]View PlainCopy 
  1. Oracle.cpp:Defines the entry point for the console application.
  2. //
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <process.h>
  6. #include <errno.h>
  7. EXEC SQL INCLUDE SQLCA;
  8. #include <sqlca.h>
  9. int main (int argc, char* argv[])
  10. {
  11. EXEC SQL BEGIN DECLARE section;
  12. VARCHAR myusername[20], mypassword[20], myserver[20];
  13. EXEC SQL END DECLARE section;
  14. printf ( "\ n Please enter user name:");
  15. Gets ((char*) Myusername.arr);
  16. Myusername.len = (unsigned short ) strlen ((char*) Myusername.arr);
  17. printf ( "\ n Please enter password:");
  18. Gets ((char*) Mypassword.arr);
  19. Mypassword.len = (unsigned short ) strlen ((char*) Mypassword.arr);
  20. printf ("\ n Please enter the server name:");
  21. Gets ((char*) Myserver.arr);
  22. Myserver.len = (unsigned short ) strlen ((char*) Myserver.arr);
  23. EXEC SQL Connect:myusername identified By:mypassword using:myserver;
  24. if (Sqlca.sqlcode < 0)
  25. printf ("\ nthe user%s succeeded in connecting to server%s!")   \ n ", Myusername.arr, Myserver.arr);
  26. Else
  27. printf ("\n%ld,%s\n", Sqlca.sqlcode, (char *) SQLCA.SQLERRM.SQLERRMC);
  28. return 0;
  29. }

Third, find the Oracle installation directory PROC.exe file, the native directory is: D:\oracle\product\10.2.0\client_2\BIN, Copy the oracle.pc file to a directory, run the cmd command line, CD to this directory, run the Proc.exe oracle.pc oracle.cpp command, and the Oracle.cpp file will be generated in the current directory.

Four, start VS2010, set up an empty control platform Oracle Project, the following note, do a good vs project configuration. Copy the oracle.cpp into the Oracle directory and add the project. Then do the configuration:

1. Database include header file path configuration

2. Database lib file directory 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. Several errors may occur:

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. Solution: extern void sqlcxt (void * *, unsigned int *,struct sqlexd *, const struct SQLCXP *), and "C" compilation after extern

3. For some other issues, look carefully at the configuration include, the Lib path is correct, and the Lib file name is correct.

Six, run the generated oracle.exe. As follows:

Original address: http://blog.csdn.net/heihei36/article/details/40149243

Go Proc Simple use case--VC connecting 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.