Very simple. NET Connection TimesTen Program

Source: Internet
Author: User
Tags oracleconnection

Same as OCI, pro*c, JDBC connection timesten. NET connection TimesTen is also very simple. Just a few more components to install.

Before you run the sample program, you need to install it first on Windows:
1. TimesTen Windows client, in this case, because the TimesTen database is on Windows, the full installation TimesTen
2. Oracle Database or Oracle Data Access components (ODAC), which contains odp.net 12.1
3. Miicrosoft Visual Studio, free Community Edition

Because. NET is based on OCI, and the OCI driver is already included in the TimesTen client installation.

Is there only one pdf:oracle associated with. NET in the TimesTen document? Data Provider for. Net-oracle timesten in-memory Database Support User's Guide, only 28 pages, stating that most of the content is the same as connecting to Oracle.

In the TimesTen installation directory under Quickstart/sample_code/odp.net There is a sample program DemoODP.cs, but for the sake of simplicity, I still provide a HelloWorld.cs program, although I have never written C # code, It feels a bit like java.

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.IO;usingOracle.DataAccess.Client;usingOracle.DataAccess.Types;usingSystem.Data;usingSystem.Data.Common; Public classhelloworld{Private Static stringConnStr ="";PrivateOracleConnection conn =NULL; Public HelloWorld() {OracleCommand Crtab =NULL; OracleCommand insert =NULL; OracleCommandSelect=NULL; OracleDataReader reader =NULL;Try{conn =NewOracleConnection (); Conn.      ConnectionString = ConnStr; Conn.      Open (); Crtab =NewOracleCommand ("CREATE Table A (a int)", conn);      Crtab.commandtype = CommandType.Text; Crtab.      ExecuteNonQuery (); Crtab.      Dispose (); Insert =NewOracleCommand ("INSERT into a values (1)", conn);      Insert.commandtype = CommandType.Text; Insert.      ExecuteNonQuery (); Insert. Dispose ();Select=NewOracleCommand ("select Max (a) from a", conn);Select.      CommandType = CommandType.Text; Reader =Select. ExecuteReader ();if(Reader. Read ()) {Object[] values =New Object[1]; Reader. GetValues (values);if(values[0] = DBNull.Value) {Console.WriteLine ("fetched Value is:"+ Convert.ToInt32 (values[0])); }} reader. Close ();Select.      Dispose (); Conn.      Close (); Conn.    Dispose (); }Catch(Exception e) {Console.WriteLine ("Test Failed");      Console.WriteLine (E.message);      Console.WriteLine (E.stacktrace); Environment.exit (-1); }  } Public Static void Main(string[]args) {connstr =//"Data source=sampledb_1122; user id=appuser; Password=appuser";       "Data Source=localhost/sampledb_1122:timesten_direct;user id=appuser; Password=appuser ";NewHelloWorld (); }}

The key in the source code is the connstr in main, which can be the TNS form, namely:

connStr = "Data Source=sampledb_1122; user id=appuser; password=appuser";

It can also be the Easy Connect form:

connStr = "Data Source=localhost/sampledb_1122:timesten_direct;user id=appuser;

Go to "developer Command Prompt"
Set Tns_admin, this path has the Tnsnames.ora file:

set TNS_ADMIN=D:\TimesTen\tt1122_64\network\admin

The TNS services we need are:

SAMPLEDB_1122 =(DESCRIPTION=(CONNECT_DATA =(SERVICE_NAME = SAMPLEDB_1122)(SERVER = timesten_direct)))

Compile:

csc /out:HelloWorld.exe /reference:D:\app\client\yyxiao\product\12.1.0\client_1\odp.net\bin\4\Oracle.DataAccess.dll HelloWorld.cs

Where D:\app\client\yyxiao\product\12.1.0\client_1\odp.net\bin\4\Oracle.DataAccess.dll is the ODAC driver file

To run the program:

Very simple. NET Connection TimesTen Program

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.