Connect to the encrypted Access database in VB6.0

Source: Internet
Author: User
I have read technical articles about how to connect to and use Access databases in Visual Basic. In fact, in professional database software development, in order to ensure the security of information in the database, encryption is often required for database files to prevent unauthorized users from opening them through other conventional means. In Visual Basic

I have read technical articles about how to connect to and use Access databases in Visual Basic. In fact, in professional database software development, in order to ensure the security of information in the database, encryption is often required for database files to prevent unauthorized users from opening them through other conventional means. In Visual Basic

I have read about how ConnectionAnd Access DatabaseIn fact, in professional DatabaseIn software development, to ensure DatabaseInformation security, usually requires DatabaseFiles are encrypted to prevent unauthorized users from opening them through other conventional means. In Visual Basic, how to establish and encrypt DatabaseOf ConnectionWhat about it? I have summarized some methods and skills in the development of the dormitory management information system of this school, and now I am writing it out to communicate with colleagues.

1. Establish Database

Because in Visual Basic 6.0 Database ConnectionMethod does not support Access 2000 format DatabaseIn this article DatabaseUse Access 97 DatabaseFor example.

Create DatabaseFor example, ssgl. mdb, and set the password, for example, "1234 ". DatabaseFiles and the project files created in VB are placed in the same directory.

If your computer only has Access 2000, You can first create ssgl. mdb in Access 2000. DatabaseAnd set the password, and then use" DatabaseUtility" DatabaseConvert to the format of Access 97.

Of course, you can also directly create a data manager in the integrated development environment of Visual Basic 6.0. DatabaseAnd then set the password in Access 97.

Through DatabaseSet the password for the file. Generally, illegal users cannot open the file by conventional means. DatabaseYes, right DatabaseInformation has played a certain role in security and confidentiality.

II, ConnectionEncrypted Access Database

In Visual Basic 6.0 DatabaseOf ConnectionThere are many technical means available, such as data controls, data objects, and data environment designers. Developers can select based on their own conditions and user needs.

The following section only describes encrypted Access. DatabaseAnd Access without encryption DatabaseIn Connection. About unencrypted DatabaseOf ConnectionReaders can refer to other materials.

1. Use Controls

① Data Control

The Data control is a built-in Data control in Visual Basic 6.0. You can set the connect, DatabaseName, and RecordSource attributes of the Data Control DatabaseOf ConnectionAnd access. Data Control ConnectionEncrypted DatabaseThere are two methods:

One way is to change the default value of the connect attribute of the Data Control in the "Properties window" to "Access"; pwd = 1234 "when designing the status, other attributes and unencrypted Access DatabaseOf ConnectionSame.

Another method is to assign values to the connect attribute through the code at runtime. For example:

Data1.connect = "; pwd = 1234"

Data1.DatabaseName = APP. path + "ssgl. mdb"

Where "1234" is Access DatabaseThe password of the ssgl. mdb file.

② Adodc Control

The Adodc control is an ActiveX control that is created from Microsoft ActiveX Data Objects (ADO) DatabaseOf Connection. Before using the Adodc control, add the Adodc control to the control toolbox. The method is as follows: in VB 6.0, select the "project" menu, click the "parts" menu item, and select "Microsoft ADO Data Control 6.0 (OLEDB)" in the "parts" dialog box that appears) "option.

Using the Adodc Control ConnectionEncrypted DatabaseThere are two methods:

One way is to set a valid ConnectionString attribute for the Adodc control in the "Property Window" during design. ConnectionString, and ConnectionAdd "; Jet OLEDB: DataBase password = 1234" to the string, and set the CommandType and RecordSource attributes of the Adodc control to the encrypted DatabaseOf Connection.

Another method is to dynamically set the ConnectionString, CommandType, and RecordSource attributes in the code at runtime to create Connection. As long as the ConnectionString attribute is valid ConnectionAdd "; Jet OLEDB: DataBase password = 1234" to the string.

2. Use Data Objects

① DAO Data Object

You must properly reference DAO data objects to establish and DatabaseOf ConnectionSelect the "project" menu in the VB integrated development environment, and then click the "Reference" menu item, in the "Reference" dialog box that appears, select the "Microsoft DAO 3.51 Object Library" option to add the DAO Data Object Type Library.

Next, you can use the following code to create an encrypted Access DatabaseSsgl. mdb Connection.

Dim db AS DataBase

Set db = OpenDataBase (App. path + "ssgl. mdb", False, False, "; pwd = 1234 ")

② ADO Data Object

ADO is a processing relationship launched by Microsoft. DatabaseNon-relational DatabaseThe latest information technology is also Microsoft's favorite for Data ConnectionAnd access technologies. In VB 6.0, Adodc controls, ADO data objects, and DataEnvironment (data environment designer) All use ADO technology, so they process encrypted Access DatabaseThe method is similar.

To correctly reference ADO Data Objects, select the "project" menu in the integrated development environment of VB 6.0, and then click the "Reference" menu item, in the "Reference" dialog box that appears, select the "Microsoft ActiveX Data Objects 2.1 Library" option to add the ADO Data Object Type Library.

Use the following code to create an encrypted Access DatabaseSsgl. mdb Connection.

Dim cnn as adodb. Connection

Dim rst as adodb. Recordset

Set cnn = New ADODB. Connection

Cnn. Provider = "Microsoft. Jet. OLEDB.3.51"

Cnn. ConnectionString = "Data Source =" & App. path & "ssgl. mdb ;"&_

"; Jet OLEDB: Database password = 1234"

Cnn. Open

③ Use DataEnvironment (data environment designer)

There are two ways to use DataEnvironment ConnectionTo encrypted Access Database:

One way is to design the status when the ConnectionSource attribute of the connection object of DataEnvironment is valid ConnectionAdd ";

Jet OLEDB: Database password = 1234"

Another method is to write the following code in the DataEnvironment_Initialize () event:

Private sub DataEnvironment_Initialize ()

Dim strconn AS string

Strconn = "Provider = Microsoft. Jet. OLEDB.3.51 ;"&_

"Data Source =" & App. path & "ssgl. mdb ;"&_

"; Jet OLEDB: Database password = 1234"

DataEnvironment1.connection1. connectionstring = strconn

End sub

The above methods and related code have been debugged, verified and passed in the Windows 98 operating system environment and Visual Basic 6.0.

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.