C # use Oracle. ManagedDataAccess. dll,
When I first came into contact with C #, since the company used Oracle databases, how to connect C # To the Oracle database became the primary knowledge point. There was no ODP at that time..
Why is this Assembly still usable in visual studio? With ODP. NET, we only need to focus on Oracle. ManagedDataAccess. dll?
1. The reminder in visual studio is outdated, because Microsoft and Oracle have a database competition relationship, and. NET updates, it seems that this Assembly has not been updated. Are you afraid to use the Assembly called when the database has been updated? Another reason that I think is very important is to use this assembly, so I cannot get rid of the fact that the Oracle client is to be installed on every client running the program. If the number of users is large, the workload for installing the client is quite large and resource-consuming;
2. Oracle later launched ODP. NET, various materials and official website said the need to install ODP. and then reference Oracle. managedDataAccess. dll, the biggest difference between it and the Assembly in visual studio is that it will be an official oracle driver along with database updates;
3. actually tested, ODP. NET installation is completely unnecessary, directly download an Oracle on the Internet. managedDataAccess. dll, which can be referenced as follows. Using this method reduces ODP. NET installation, regardless of the number of digits of the operating system, the most important thing is to reduce the installation of the Oracle client;
Where can I download Oracle. ManagedDataAccess. dll? How can I know if Oracle. ManagedDataAccess. dll is updated? At this time, the most powerful development tool in the universe was launched!
After the installation is complete, you can refer to the Code, and if there is any update, you can see it at any time. In terms of programming, it is not much different from the previous use of the System. Data. OracleClient assembly. Basically, you just need to make a few changes to the Code that used the System. Data. OracleClient assembly before.
1. The connection string is used instead of the service name of the oracle client;
2. Changes to several namespaces;
Below is the encapsulation of Common Database Operations
Using System; using System. collections. generic; using System. linq; using System. text; using System. configuration; using Oracle. managedDataAccess. client; using System. data; using System. IO; using System. collections; using System. diagnostics; using Oracle. managedDataAccess. types; namespace OracleDemo {public class OracleHelper {private static string connStr = "User Id = admin; Password = 123; data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.0.1) (PORT = 1521) (CONNECT_DATA = (SERVICE_NAME = test ))) "; # region executes the SQL statement and returns the affected rows public static int ExecuteNonQuery (string SQL, params OracleParameter [] parameters) {using (OracleConnection conn = new OracleConnection (connStr) {conn. open (); using (OracleCommand cmd = conn. createCommand () {cmd. commandText = SQL; cmd. parameters. addRange (parameters); return cmd. executeNonQuery () ;}}# endregion # region executes the SQL statement and returns the DataTable. It is only used to execute the public static DataTable ExecuteDataTable (string SQL, params OracleParameter [] parameters) {using (OracleConnection conn = new OracleConnection (connStr) {conn. open (); using (OracleCommand cmd = conn. createCommand () {cmd. commandText = SQL; cmd. parameters. addRange (parameters); OracleDataAdapter adapter = new OracleDataAdapter (cmd); DataTable datatable = new DataTable (); adapter. fill (datatable); return datatable; }}# endregion }}
The following code is called
string sqlString = "Select a.col1,a.col2 From test a Where a.id=:id"; DataTable dt = OracleHelper.ExecuteDataTable(sqlString,new OracleParameter(":id",1));
After the program is compiled, the directory is roughly as follows:
At this time, copy the Debug folder to the target client and run it directly (the premise is that the target client has a. NET Framework on the computer.