Automatically registering Access ODBC

Source: Internet
Author: User
Tags ini odbc access
Access|odbc
I see a lot of programs on the Internet that offer this service, but I don't like pop-ups and complex process calls.
By flipping through the registry, you think of a method that registers only through key values. Of course, the prerequisite is that you need to test whether the database can be used.
ULONG Function Uf_regodbc (string odbcname,string filename,int flag)

To build an ODBC data source based on the MDB filename and ODBC DSN name
Flag = 1 Modifying original data source
Falg=0 New Data source
STRING Driverfile
STRING UID
SetNull (UID)
String Cdirect
Cdirect=getcurrentdirectory ()
If Right (Cdirect, 1) <> ' then cdirect=cdirect+ ' \ '
if (odbcname= ') or (filename= ') then
MessageBox ("Info", "file name or data source name cannot be empty when creating or modifying a data source!")
Return-1
End If

If not fileexists (filename) Then
MessageBox ("Info", ' data source registration or modification failed, please fill in the file name correctly! ')
Return-1
End If
If not FileExists (Getsystemroot () + "System32\odbcjt32.dll") Then
FileCopy (cdirect+ "\mytool\odbcjt32.dll", Getsystemroot () + "System32\odbcjt32.dll", True)
End If
Driverfile=getsystemroot () + "System32\odbcjt32.dll"



If Flag=0 Then
New Data source
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname," DBQ ", Regstring!,filename)
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname," DRIVER ", Regstring!,driverfile)
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname," DriverID ", regulong!,25)
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname," FIL ", regstring!," MS Access; ")
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname," Safetransactions ", regulong!,0)
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname, UID", regstring!, "")
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname+", "\engines\jet", "ImplicitCommitSync", regstring!, "" "
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname+", "\engines\jet", "MaxBufferSize", regulong!,2048)
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname+", "\engines\jet", "PageTimeout", regulong!,5)
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname+" \engines\jet "," UserCommitSync ", regstring!, ' YES ')
ELSE
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") Ini\ "+odbcname," DBQ ", Regstring!,filename)

End IF
Registryset ("HKEY_CURRENT_USER Oftware\odbc\odbc.") INI\ODBC Data Sources ", odbcname,regstring!, Microsoft Access Driver (*.mdb)")

Of course, if the database has a username and password, you need to write two key values. by analogy. The registration of ASA library is the same. There are also many online. No longer in the classification.


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.