PB Connection Database

Source: Internet
Author: User
Tags ole

Database transaction connection, before very little contact, do things are using the local database, not used remote, database transaction connection is also using the default, so it caused the basic knowledge of the lack of understanding, is actually very simple things.

First you have to set up the database over there, ODBC or OLE db or, in short, the data source to build up first. And then just a few things about the code in the program:

SQLCA. DBMS = "OLE DB"
SQLCA. Logid = Gs_logid
SQLCA. Logpass=gs_logpass
SQLCA. Autocommit = False
Sqlca.dbparm = "provider= ' SQLOLEDB ', datasource= '" +gs_datasource+ "', timeout=" +string (ltime) + ", providerstring= ' Database= "+gs_database+" "

The first line is the name of the data manufacturer, which is plainly the way you connect. Then these variables are required: Gs_logid user name, Gs_logpass password (nullable), Gs_datasource data source, Gs_database database. The value of timeout is the time to set up the connection database. Assign these variables, and then use the statement connect using SQLCA can be practiced to the database, whether remote or local, the database will be automatically to you, but the database connection is very resource-intensive, if you do not open the database or network interruption, it is likely to cause the machine is very card.

That day also compiled a test program, is connected to a remote database, if disconnected on the count of +1, very simple one thing, done several times. is actually a timer () event, let the database constantly judge the connection.

W_testing.setfocus ()
int Lcount
Select COUNT (1) Into:lcount from Sys_user using Sqlca;

If sqlca.sqlcode= 0 Then
st_4.text= "Connected"
Ib_lastconnect=true
Else
If Ib_lastconnect=true Then
gl_counter++
Sle_1.text=string (Gl_counter)
W_main.sle_1.text=string (Gl_counter)
End If
Ib_lastconnect=false
St_4.text= "Disconnected, trying to reconnect"

SQLCA. DBMS = "OLE DB"
SQLCA. Logid = Gs_logid
SQLCA. Logpass=gs_logpass
SQLCA. Autocommit =true
Sqlca.dbparm = "provider= ' SQLOLEDB ', datasource= '" +gs_datasource+ "', timeout=15,providerstring= ' database=" +gs_ Database+ "'"
Disconnect using Sqlca;
Connect using Sqlca;

End If


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.