C# uses OracleClient to connect to Oracle database

I still use Microsoft's System.Data.OracleClient object to connect to Oracle (v12). Because of the old code, I didn't use the relatively new ODP.NET. After a few days of tossing, it didn't work at first. The last two days have finally been tossed. .

Brief summary of the main points:

1) The server should be configured correctly.

Configure the listener through the "Net Configuration Assistant". When adding a listener, you need to distinguish it from the existing listener's name (LISTENER) and port number (default 1521). At the same time, this can also be updated and deleted in the file (\NETWORK\ADMIN\listener.ora in the installation directory).

2) The listener of the server should be started

The corresponding can be started using LSNRCTRL start in the server bin directory. If it is activated, it will prompt

3) The corresponding user name and password, the service name (not SID) should be remembered clearly, and the authority should be sufficient

First, log in to sqlplus as an administrator to update user information. Remember to remember that the user name to be updated starts with C##, also on the client side. Grant connnect, resource and other permissions (not too much involved for the time being).

4) Downloaded OracleClient

It can be downloaded from the official website (account password is required to log in), or the online disk (link: https://pan.baidu.com/s/1IOijGWMOYVv-S3OZsjAn7g password: 7lvl) after decompression, there is this folder in it: instantclient_12_2) The version must be correct , otherwise it will prompt a version problem, which seems to be related to the version of the compiled object, and there is no relationship between the test and the server version (it is reasonable to say that it is irrelevant, it is the network anyway). Write this folder path into the PATH environment variable, or copy three dlls (oci.dll, oraociei12.dll, oraons.dll, the second of which is 190M huge) to the program running directory (subdirectories do not seem to work), Basically done.

5) Use the connection string

Pay attention to user_name, password, ip_host, service_name, you can view the string of the corresponding service in the server's tnsnames.ora

User ID=user_name;Password=password;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = ip_host)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = service_name)))

I have referred to a lot, including the new way of using OracleClient link in C#, several ways of connecting to Oracle in C# , why should I add C## before the user name when creating a new user in Oracle 12C?

I haven't been in contact with Oracle. I have learned so much for a week. There are true and false, and I slowly explore.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325333558&siteId=291194637