PetaPoco Uses ODP. NET Managed Driver to connect to Oracle and petapocoodp.net

Source: Internet
Author: User
Tags connectionstrings oracle developer

PetaPoco Uses ODP. NET Managed Driver to connect to Oracle and petapocoodp.net

A few years ago, I used PetaPoco to work on an Oracle project. It was very troublesome to install the oracle client during development. After the environment is debugged, the system is not reinstalled until the end of the project. Recently, another requirement is to read oracle, but the environment is no longer ......

Re-configure it. First, use nuget to download and install PetaPoco. I didn't expect the latest version to change a lot. It seems that there are a few classes missing, and there is no time to wait, so I downloaded an old version 5.0.1. But if you really don't want to install the oracle client, you just want to use Oracle. DataAccess. dll for direct access.

Add a database string to the App. config file:

<ConnectionStrings>

<Add name = "MyDbContext"

ConnectionString = "Data Source = (DESCRIPTION =

(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = xxx) (PORT = 1521 )))

(CONNECT_DATA = (SERVICE_NAME = ORCL )));

User Id = scott; Password = xxx ;"

ProviderName = "Oracle. DataAccess. Client"/>

</ConnectionStrings>

 

Modify the following parts of the T4 template Database. tt:

ConnectionStringName = "MyDbContext"; // Uses last connection string in config if not specified

Namespace = "Domain. Models ";

RepoName = "MyDbContext ";

 

Save, no doubt the error is returned:

// Configure //-----------------------------------------------------------------------------------------

// Failed to load provider 'oracle. DataAccess. client'-the requested. Net Framework Data Provider cannot be found. It may not be installed.

// Configure //-----------------------------------------------------------------------------------------

 

The driver is still not installed. When searching for a solution, find these two articles:

. NET Oracle Developer-ODP. NET Managed officially launched

 

Oracle: ODP. NET Managed

 

It turns out that Oracle has launched a hosted driver that does not distinguish between 32-bit and 64-bit, which should be more convenient. The download on the Oracle official website is disgusting. Search for odp.net. managed from nuget according to the description:

After installation, modify the provider of the database connection string:

ProviderName = "Oracle. ManagedDataAccess. Client"

 

Again, the error is the same. The driver Oracle. ManagedDataAccess. Client cannot be found:

// Configure //-----------------------------------------------------------------------------------------

// Failed to load provider 'oracle. ManagedDataAccess. client'-the requested. Net Framework Data Provider cannot be found. It may not be installed.

// Configure //-----------------------------------------------------------------------------------------

 

It seems that nuget cannot be directly installed. You still have to go to the official website and find this page:

Http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html

A bunch of things !!! Which of the following ???

Here I am:

After decompression, there are several folders and dll files. If we have installed the dll through nuget, there is an install_odpm.bat file. It seems we have to install it. Run it directly, and click it to run it again.

Run cmd first. Run cmd to find the bat and run it:

In the past, it was not possible to run directly, but also to add parameters. Run in the third method and report an error:

It seems that you need to enable the Administrator permission and run cmd in administrator mode.

Open this bat and you can see that several files are copied to the system directory, and tnsnames. ora files are automatically added.

Run Database. tt again, and other errors will be reported this time:

// Configure //-----------------------------------------------------------------------------------------

// Failed to read database schema-'user id' is invalid connection string attribute

// Configure //-----------------------------------------------------------------------------------------

 

It seems that the driver has been loaded normally. Why is this error reported?

After looking for the reason for half a day, it turns out that the database connection string cannot have line breaks! Otherwise, the PetaPoco T4 template cannot be read ......

 

Also, the latest version on the oracle official website is 12.1.0.2.4, and the version on nuget does not seem to be updated yet.

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.