Delphi7 read ini configuration connection Oracle10g

Source: Internet
Author: User

Recently, I learned about Delphi and needed to configure the connection to the Oracle database. However, many methods on the Internet do not contain IP addresses. I finally found it for a long time, but I forgot where I found it. Share it with you!

Call this function when you need to introduce inifiles to create a form.

Add inifiles to the user

Procedure tform1.formcreate (Sender: tobject );
Const
Connstr = 'provider = oraoledb. oracle.1; Password = % s; persist Security info = true; user id = % s; Data Source = (description = (address_list = (address = (Protocol = TCP) (host = % s) (Port = % s) (CONNECT_DATA = (SERVICE_NAME = % s )))';
VaR
INIFILE: Tinifile;
IP, port, Sid, username, password, filename, filepath: string;
Begin
Filepath: = extractfilepath (paramstr (0 ));
Filename: = filepath + 'dbconfig. ini ';
If fileexists (filename) then
Begin
INIFILE: = Tinifile. Create (filename );
IP: = INIFILE. readstring ('database', 'IP', '2017. 0.0.1 ');
Port: = INIFILE. readstring ('database', 'Port', '123 ');
Sid: = INIFILE. readstring ('database', 'sid ', 'orcl ');
Username: = INIFILE. readstring ('database', 'username', 'admin ');
Password: = INIFILE. readstring ('database', 'Password', 'admin ');
Form1.adoconnection1. connectionstring: = format (connstr, [password, username, IP, port, Sid]);
End
Else
Showmessage ('The dbconfig. ini file is not found. Check the file! ');
End;

 

INI File Content

[Database]
IP = 127.0.0.1
Port = 1521
SID = orcl
Password = Admin
Username = Admin

// Note: extractfilepath (paramstr (0) + 'dbconfig. ini '); it seems that I cannot write it here. The result is not followed by the file name.

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.