Use isline framework to Develop ASP. Net Program 2-Use dataprovider to access data (on)

Source: Internet
Author: User

PreviousArticleWe mentioned the dataprovider module, which completes operations on various data sources. compatible data sources include SQL Server databases, Oracle databases, XML files, text files, and config site configuration files. Shows the basic constraint relationships:

Figure 2.1 basic constraints of dataprovider

This module mainly includes the following namespaces:

● Isline. Data. containerdefiner namespace:

Isline. data. containerdefiner is an extension of dataprovider, which defines some ADO. common Data Objects in. Net, which appear in the upper layer as the container role. It can cache some columns and persist data according to these policies, this namespace depends on the namespace isline. httpcontent. hcdatatypeenum.

The main member class is containerdefine, which implements the isqlcontainer, ioraclecontainer, ifilecontainer, and idisposable interfaces. filecontent method. Return or set a filecontent. The filecontent is a member of the ifilecontainer interface and contains Cache Optimization Options. This option can be specified during instantiation; other methods include sqldatareader, oracledatareader, dataset, datarow, and dispose.. net, but it also contains some optimization operations. For example, when large data is stored, dataprovider automatically enables the cache mechanism to improve data read efficiency.

● Isline. Data. dataprovider namespace:

This namespace is the subject of dataprovider, which completes data storage operations. It depends on namespaces: isline. Security. cryptography, isline. Data, and isline. Data. configuration. The main member classes include dbprovider, oracleprovider (Implementation interface ioracleprovider), sqlprovider (Implementation interface isqlserverprovider), fileprovider, xmlprovider, textprovider, and suitconfigprovider.

You can use a custom factory, or use the method defined in isline framework to process data. Before using dataprovider. configure the following nodes in config and add them between <configsections> </configsections>:

<Isline. Data. Configuration>
<Databaseconnection>

<Dbtype> isline. Data. datatypeenum. databasetype. sqlserver </dbtype>
<Server> Server IP address </Server>
<Userid> SA </userid>
<Pwdtype> cryptography. Decrypting </pwdtype>

<PWD> 111111 </pwd>
<Database> UML </database> // sqlserver only
</Databaseconnection>
</Isline. Data. Configuration>

Databaseconnection indicates the database type, pwdtype indicates the Password Encryption Policy, and isline provider has a built-in 3 Policy for selection, as shown in the configuration file. The above example is for sqlserver. For oralce databases, the above format configuration is also used, but slightly changed:

Change dbtype to isline. Data. configuration. oracleconnectstring; specify the TNS alias for the server node. The additional content in the otherplus node will be sent to the database as part of the Oracle connection string.

<Otherplus> provider = msdaora.1; persist Security info = false; </otherplus>

The above method is a structured configuration method. If you think this configuration is troublesome, you can use the following simple configuration method to avoid node configuration:

SQL Server Configuration:

<Add key = "isline. data. configuration. sqlserverconnectstring "value =" Data Source = Server IP; user; Password = 111111; Integrated Security = no; enlist = false; pooling = true; "/>

Oracle configuration:

<Add key = "isline. data. configuration. oracleconnectstring "value =" Data Source = TNS alias; user; Password = 111111; Integrated Security = no; enlist = false; pooling = true; "/>

You can choose one of the two configuration methods mentioned above. After the node is configured, call it using the following methods: connection-oriented and non-connection-oriented (for example, dataset/Reader/adapter) it must be instantiated before use and called after use. the dispost () method releases resources. dispost () is a method rewritten by dataprovider. Once called, all resources, including connection, command, and datareader, will be released, for non-connection operations, you can directly call them. If datareader and adapter are used for connection-oriented operations, simply execute SQL statements as non-connection operations. For example, to access a database, simply execute the following SQL statements:

Oracleprovider. executenonquery () or sqlprovider. executenonquery (). Some methods need to be instantiated before they can be used. For example:

Oracleprovider op = new oracleprovider ();

Op. somefunc ();

If you want more detailed methods and parameter lists, visit my blog.

The following lists some execution instances:

1. Execute an SQL statement:

Oracleprovider. executenonquery (SQL );

2. Execute a batch of SQL statements using transactions:

Oracleprovider. executenonquery (SQL, true, commandtype. Text, null );

The second parameter indicates opening the transaction and executing the statement passed in by the first parameter. .

3. Execute a stored procedure:

Oracleprovider. executenonquery (storedprocedurename, null, commandtype. storedprocedure, oracleparam );

4. Return a datareader

New oracleprovider (). executereader (SQL );

6. Return a dataset using the specified connection

New oracleprovider (). executedataset (SQL, "connectionstr", 0 );

The above are just a few simple examples. In short, using dataprovider, you can control the database through configuration.CodeThere are only operation statements at the level, and there is no database connection or configuration statement.

In the next issue, we will introduce the last part of data access.

This article has been published simultaneously in the software report and cannot be reproduced by any personal media.

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.