Microsoft. Practices. EnterpriseLibrary connects to Oracle

Source: Internet
Author: User

1. After the dll is referenced for installation, find the following dll in the installation directory: copy it to the project directory first, and reference it. 2. Configure the configuration file for connecting to the database. You can use program configuration or generate a blank document for manual configuration ., Step 1: Run entlibconfig.exe in the installation directory. Step 2. Select the blocks menu to configure database connection. Step 3: Configure database connection. You can also directly save File-save as an empty config File for manual configuration: here, an empty configuration is saved for manual configuration. The empty configuration is as follows: [html] <configuration> <configSections> <section name = "dataConfiguration" type = "Microsoft. practices. enterpriseLibrary. data. configuration. databaseSettings, Microsoft. practices. enterpriseLibrary. data, Version = 5.0.414.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "requir EPermission = "true"/> </configSections> <dataConfiguration defaultDatabase = "Connection String"/> <connectionStrings> <add name = "Connection String" connectionString = "Database = Database; server = (local) \ SQLEXPRESS; Integrated Security = SSPI "providerName =" System. data. sqlClient "/> </connectionStrings> </configuration> <configSections> <section name =" dataConfiguration "type =" Microsoft. panel Ctices. enterpriseLibrary. data. configuration. databaseSettings, Microsoft. practices. enterpriseLibrary. data, Version = 5.0.414.0, Culture = neutral, publicKeyToken = 31bf3856ad364e35 "requirePermission =" true "/> </configSections> <dataConfiguration defaultDatabase =" Connection String "/> <connectionStrings> <add name =" Connection String "connectionString =" Database = Database; server = (local) \ SQLEXPRESS; Integrate D Security = SSPI "providerName =" System. Data. SqlClient "/> </connectionStrings> </configuration> for manual configuration, oracle is used as an example. As follows: [html] <? Xml version = "1.0"?> <Configuration> <configSections> <! -- Add and configure the enterprise database (1) --> <section name = "dataConfiguration" type = "Microsoft. practices. enterpriseLibrary. data. configuration. databaseSettings, Microsoft. practices. enterpriseLibrary. data, Version = 5.0.414.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "requirePermission =" true "/> </configSections> <! -- Add and configure the enterprise database (2) --> <dataConfiguration defaultDatabase = "Oracle. ConnectionString"/> <! -- Add and configure the enterprise database (3) --> <connectionStrings> <add name = "Oracle. connectionString "connectionString =" Data Source = database name; Persist Security Info = True; User ID = User name; Password = Password; Unicode = True "providerName =" System. data. oracleClient "/> </connectionStrings> </configuration> <? Xml version = "1.0"?> <Configuration> <configSections> <! -- Add and configure the enterprise database (1) --> <section name = "dataConfiguration" type = "Microsoft. practices. enterpriseLibrary. data. configuration. databaseSettings, Microsoft. practices. enterpriseLibrary. data, Version = 5.0.414.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "requirePermission =" true "/> </configSections> <! -- Add and configure the enterprise database (2) --> <dataConfiguration defaultDatabase = "Oracle. ConnectionString"/> <! -- Add and configure the enterprise database (3) --> <connectionStrings> <add name = "Oracle. connectionString "connectionString =" Data Source = database name; Persist Security Info = True; User ID = User name; Password = Password; Unicode = True "providerName =" System. data. oracleClient "/> </connectionStrings> </configuration> is ready. these preparations are complete. Let's take a look at how to use them in the code. Test reading here. Of course, all other operations are the same. [Csharp] public class OracleSqlHelper {private static Database db = null; public static DataSet GetDataTable (string commandText) {try {DataSet resultDataSet = null; db = DatabaseFactory. createDatabase (); // create a database connection. resultDataSet = db. executeDataSet (CommandType. text, commandText); // execute return resultDataSet;} catch (Exception ex) {return null; throw ex ;}} public class OracleDataProvider {publ Ic static DataTable TestReadTable (string id) {DataTable dataTable = null; try {string commandText = "select tu. name from tabUser tu "; DataSet resultTable = OracleSqlHelper. getDataTable (commandText); int table = resultTable! = Null? ResultTable. tables. count: 0; if (table> 0) {dataTable = resultTable. tables [0] ;}} catch (Exception e) {throw e;} return dataTable ;}} public class OracleSqlHelper {private static Database db = null; public static DataSet GetDataTable (string commandText) {try {DataSet resultDataSet = null; db = DatabaseFactory. createDatabase (); // create a database connection. resultDataSet = db. executeDataSet (CommandType. text, CommandText); // execute return resultDataSet;} catch (Exception ex) {return null; throw ex ;}} public class OracleDataProvider {public static DataTable TestReadTable (string id) {DataTable dataTable = null; try {string commandText = "select tu. name from tabUser tu "; DataSet resultTable = OracleSqlHelper. getDataTable (commandText); int table = resultTable! = Null? ResultTable. tables. count: 0; if (table> 0) {dataTable = resultTable. tables [0] ;}} catch (Exception e) {throw e;} return dataTable ;}} call object result = OracleDataProvider. testReadTable ("110"); of course, this is only the use of the enterprise database to connect to the database, so you can use the dll replication separately. It is certainly not that simple for large-scale applications. The configuration file of all features required for the installation of dlland the use of entlibconfig.exe to configure the block.

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.