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
- Oracle.cpp:Defines the entry point for the console application.
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <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);
- printf ( "\ n Please enter password:");
- Gets ((char*) Mypassword.arr);
- Mypassword.len = (unsigned short ) strlen ((char*) Mypassword.arr);
- printf ("\ 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 succeeded in connecting to server%s!") \ n ", Myusername.arr, Myserver.arr);
- Else
- printf ("\n%ld,%s\n", Sqlca.sqlcode, (char *) SQLCA.SQLERRM.SQLERRMC);
- return 0;
- }
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