Asp.net connection to oracle

Source: Internet
Author: User

This article introduces how to connect asp.net to oracle and summarizes some connection problems and methods. For more information, see.

Two Methods for connecting. net to oracle Database
1. Install the oracle client and connect to oracle

You must configure tnsnames. ora in the client % oracle_client_home % network/admin/. Take Service name aa as an example. The service names and connection strings of the client and the server must be consistent. Service name configuration example:

The Code is as follows: Copy code

A =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = helen) (PORT = 1521 ))
)
(CONNECT_DATA =

(SERVER = DEDICATED)
(SERVICE_NAME =)
)
)

Program code:

The Code is as follows: Copy code

String connOra = "Data Source = a; User ID = a; password = a; Unicode = True ";

OracleConnection conn = new OracleConnection (connOra );
Conn. Open ();
If (conn. State = ConnectionState. Open)
Response. Write ("DataOracle. aspx conn open success ");
Else

Response. Write ("DataOracle. aspx conn open failure ");

 
2. Connect to oracle without installing the oracle client

You do not need to configure tnsnames. ora to write the host, port, and database ID (SID) to the connection string. Other connections are the same as above.

The new connection string is:

The Code is as follows: Copy code

Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = helen) (PORT = 1521) (CONNECT_DATA = (SID = ))); user ID = a; password = a; Unicode = True

The company uses oracle10g and vs2010, all of which are 32-bit.

1) oracle10g cannot be directly installed in 64-bit win7. Solution: Right-click the installation and startup exe file and choose "compatibility"> select "run this program with compatibility" --> select "winxp, you can install it after saving it.

2) previously, we used the winxp32-bit system to connect strings like this.

The Code is as follows: Copy code

<Add name = "SQLMembershipConnString2" connectionString = "Data Source = ORCL; User Id = system; Password = 123456;" providerName = "Oracle. DataAccess. Client"/>

After changing to the current 64-bit Windows 7, it has been unable to run. After one day, I realized that it was a connection string problem. The error message is that the oracle client version is not high enough. No matter how the connection string is changed, the error message is the same. Baidu has found many articles about the reason for insufficient permissions (not sure whether this is the cause ), after the change, I still had the same problem. It took me a day !!, Later, I downloaded the odp.net Component of oracle. All the 32-bit 64-bit tossing errors were prompted, and searching online based on the error prompt could not be solved. Think that the framework class is compatible with odp.net. Later, he carefully read the description of odp.net, and tried to use

The Code is as follows: Copy code

<Add name = "SQLMembershipConnString3" connectionString = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.253.11) (PORT = 1521 )) (CONNECT_DATA = (SID = HZDB); User Id = test; Password = 123456; "providerName =" Oracle. dataAccess. client "/>

Such a string has not been connected for a long time because of a large number of changes. Just as I plan to give up going home and reinstalling the 32-bit system, the error message "table or view not found" is displayed on the page! Then we found the root cause of the problem: the connection string is incorrect. Then change to System. Data. OracleClient.
After testing, we found that another method is also possible:

The Code is as follows: Copy code

<Add name = "SQLMembershipConnString" connectionString = "Data Source =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.253.128) (PORT = 1521 ))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
); User Id = test; Password = 123456;
"ProviderName =" Oracle. DataAccess. Client "/>


About

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.