Summary of INSERT and select for vs2012 connection oracle11g and data

Source: Internet
Author: User
Tags dotnet oracleconnection oracle developer

Download link for Oracle 11g required driver odtwithodac1120320_32bit, download link for http://www.oracle.com/technetwork/topics/dotnet/ Utilsoft-086879.html

Install Odtwithodac1120320_32bit, choose to install the product during installation is only need to select Oracle Client

Reprint : Install ODTwithODAC112012, ora-12560:tns: Protocol Adapter error

Reference:http://blog.csdn.net/tan_yixiu/article/details/6762357

Operating system: Windows7

Development tools: VS2012

Database: oracle11g

ORA-12560:TNS: Protocol Adapter error occurred after installing odac:odtwithodac112012

ODTwithODAC112012:http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html

Enter the system environment variable setting, view the path, and discover that the Oracle client is installed at the same time that the ODAC is installed.

The path that is generated when installing ODAC is found at the top of the path path after installation is complete.

F:\app\Administrator\product\11.2.0\client_1;

F:\app\Administrator\product\11.2.0\client_1\bin;

At this point the path is: F:\app\Administrator\product\11.2.0\client_1; F:\app\Administrator\product\11.2.0\client_1\bin; E:\app\administrator\product\11.2.0\dbhome_1\bin;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem ;%systemroot%\system32\windowspowershell\v1.0\;

These two paths are placed in front of the oracle11g database path, resulting in Ora-12560:tns: Protocol adapter error

F:\app\Administrator\product\11.2.0\client_1 the newly added path; F:\app\Administrator\product\11.2.0\client_1\bin (after the Oracle database path) resolves the ora-12560:tns: Protocol adapter error.

For example: Modify path to: e:\app\administrator\product\11.2.0\dbhome_1\bin;%systemroot%\system32;%systemroot%;%systemroot%\ System32\wbem;%systemroot%\system32\windowspowershell\v1.0\; F:\app\Administrator\product\11.2.0\client_1; F:\app\Administrator\product\11.2.0\client_1\bin;

Fix Ora-12560:tns: Protocol adapter error.

Next Configure the Oracle client, otherwise VS2010 cannot connect to Oracle data

Locate the installation directory for the Oracle database, and then locate the following directory in it

For example: My installation on E-drive

E:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN

Two files in which the following tags are found: Tnsnames.ora and Sqlnet.ora

The two files are then copied to the following directory under the installation directory of Oracle Developer Tools for Visual Studio. NET.

For example: My installation on the F-drive

F:\app\Administrator\product\11.2.0\client_1\Network\Admin

Then you can restart the machine. (Note I this Oracle database is installed on the same server as Oracle Developer Tools for Visual Studio. NET).

vs2012 Connection oracle11g ( I practice )

Connect to Oracle:

public class DBHelper
{
Public Const string CONSTR = "DATA source=orcl; USER Id=scott; Password=tiger ";
}

To have this using System.Data.OracleClient;

Select Example: (No typesetting)

Public Loginuser Finduserbyloginid (string LOGINID)//Find T_users table by LOGINID
{
String cmdstr = "Select Loginid,loginpwd from T_users where Loginid=:loginid";
using (OracleConnection conn = new OracleConnection (DBHELPER.CONSTR))
{
Conn. Open ();
using (oraclecommand cmd = new OracleCommand (CMDSTR, conn))
{
Cmd. Parameters.addwithvalue ("LOGINID", LOGINID);
using (OracleDataReader dr = cmd. ExecuteReader ())
{
if (Dr. Read ())
{
Loginuser u = new Loginuser ();
U.loginid = convert.tostring (dr["LOGINID"]);
U.loginpwd = convert.tostring (dr["loginpwd"]);
return u;
}
return null;
}
}
}

}

Insert Example: (No typesetting)

Public int submitregisterinformation (RegisterUser u)//Submit user registration information
{
String cmdstr = @ "INSERT into T_users
(LO Ginid
, Loginpwd
, register_time)
VALUES
(: LOGINID
,: Loginpwd
, To_date (: Register_time, ' Yyyy-mm-dd hh24:mi:ss ')) "; //register_time is a date type in the Oracle database, but in Oracle it shows that the problem is detailed later
using (OracleConnection conn = new OracleConnection (DBHELPER.CONSTR))
{
Conn. Open ();
using (oraclecommand cmd = new OracleCommand (CMDSTR, conn))
{

String register_time = DateTime.Now.ToShortDateString ();
Register_time + = DateTime.Now.ToShortTimeString ();

String register_time = DateTime.Now.ToLongDateString (). ToString ();
Register_time + = DateTime.Now.ToLongTimeString (). ToString ();

Cmd. Parameters.addwithvalue ("LOGINID", U.loginid);
Cmd. Parameters.addwithvalue ("Loginpwd", u.loginpwd);
Cmd. Parameters.addwithvalue ("Register_time", register_time);
return CMD. ExecuteNonQuery ();
}
}
}

Summary of INSERT and select for vs2012 connection oracle11g and data

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.