Implement online switching of databases used by the program

Source: Internet
Author: User

My idea is to use system. Data. Common; without directly specifying data to provideProgramCreate the dbconnection class and dbcommand by passing parameters.

CodeIt is also very simple. It is almost the same as it is:

Type temptype = type. GetType ("system. Data." + typename + ", system. Data, version = 2.0.0.0, culture = neutral, publickeytoken = b77a5c561934e089 ")

Object tempobj = activator. createinstance (temptype );

_ Connetion = (dbconnection) tempobj;

Typename is the input parameter, such as oledb. oledbconnection,

_ Connetion is an empty dbconnection, which can be output as a property in the class.

In this way, as long as typename is controlled, the database can be switched online. We can put typename and connection fields into XML or another database (I select access, in this way, you only need to perform operations on the database in the management background to switch the main database of the program.

All of the above are passed in vs2005. Ms SQL Server2000 Access 2003 Oracle 9i tested

Hope to give some inspiration to some friends

 

 

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.