Automatically create ODBC

Source: Internet
Author: User
Automatically create ODBC

Automatic ODBC creation is based on direct write operations on the Windows registry.

Steps:

1. Create a function:

Gf_create_odbc (string as_odbc_name, string as_odbc_type, string as_path)

String ls_key, ls_key1

Ls_key = 'HKEY _ CURRENT_USER/software/ODBC. INI/'+ as_odbc_name

Ls_key1 = 'HKEY _ CURRENT_USER/software/ODBC. INI/ODBC Data Sources'

If as_odbc_type = 'dbf' then

Registryset (ls_key, 'driver ', "C:/Windows/system/pbdbf12.dll ")

Registryset (ls_key, 'description', "automatically generate ODBC '")

Registryset (ls_key, 'database', as_path)

Registryset (ls_key, 'createtype', "foxpro25 ")

Registryset (ls_key, 'locking', "record ")

Registryset (ls_key, 'lockcompatibility ', "Fox ")

Registryset (ls_key, 'fileopencac', "1 ")

Registryset (ls_key, 'cachesize', "4 ")

Registryset (ls_key, 'datafileextension', "DBF ")

Registryset (ls_key, 'intlsort ', "C: 0 ")

Registryset (ls_key, 'uselongnames ', "1 ")

Registryset (ls_key, 'uselongqualifiers', "1 ")

Registryset (ls_key, 'applicationusingthreads', "1 ")

Registryset (ls_key1, as_odbc_name, "PB intersolv OEM 3.01 32-bit dbasefile (*. DBF )")

End if

If as_odbc_type = 'sqlany' then

Registryset (ls_key, 'driver ', as_path + "wod50t. dll ")

Registryset (ls_key, 'description', "automatically generate ODBC '")

Registryset (ls_key, 'uid', "dba ")

Registryset (ls_key, 'pwd', "SQL ")

Registryset (ls_key, 'start', as_path + 'dbeng50 ')

Registryset (ls_key, 'databasefile', as_path + as_odbc_name + '. db ')

Registryset (ls_key, 'databasename', as_odbc_name)

Registryset (ls_key, 'autostop', "yes ")

Registryset (ls_key1, as_odbc_name, "Sybase SQL Anywhere 5.0 ")

End if

If as_odbc_type = 'foxpro' then

Registryset (ls_key, 'defaultdir', as_path)

Registryset (ls_key, 'description', as_odbc_name + "ODBC '")

Registryset (ls_key, 'driver ', 'c:/Windows/system/odbcjt32.dll ')

Registryset (ls_key, 'driverid', regulong !, 280)

Registryset (ls_key, 'fil ', "Foxpro 2.0 ")

Registryset (ls_key, 'safety ransactions', regulong !, 0)

Registryset (ls_key, 'uid ',"")

Registryset (ls_key + '/engines/xbase', 'collatingsequence', 'ascii ')

Registryset (ls_key + '/engines/xbase', 'deleted', regulong !, 1)

Registryset (ls_key + '/engines/xbase', 'implicitcommitsync', 'yes ')

Registryset (ls_key + '/engines/xbase', 'pagetimeout', regulong !, 600)

Registryset (ls_key + '/engines/xbase', 'statistics', regulong !, 0)

Registryset (ls_key + '/engines/xbase', 'threads', regulong !, 3)

Registryset (ls_key + '/engines/xbase', 'usercommitsync', 'yes ')

Registryset (ls_key1, s_dbfname, "Microsoft FoxPro Driver (*. DBF )")

End if

...

2. Create relevant ODBC information before establishing a connection, as shown in figure

...

String ls_dbfname = "C:/foxprow/Database"

Gf_create_odbc ('testdbf', 'foxpro', ls_dbfname)

Sqlca. DBMS = "ODBC"

Sqlca. autocommit = false

Sqlca. Database = 'testdbf'

Sqlca. dbparm = "connectstring = 'dsn = testdbf '"

Connect using sqlca;

If sqlca. sqlcode <> 1 then

MessageBox ('error', 'cannot connect to the specified database file! ('+ Ls_dbfname +') ', stopsign !)

Halt close;

End if

...

3. Delete the ODBC settings;

Create a public function gf_erase_odbc (string as_odbc_name)

...

After the preceding steps, you do not need to use the ODBC tool in the control panel.

You can consider the following improvements:

1. added parameter settings for ODBC function creation;

2. Create an ODBC setting tool and run it in the system;

3. ODBC driverProgramYou can specify a specific directory or file.
 

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.