Use API functions to implement odbc dsn setup in vfp9.0

Source: Internet
Author: User
Tags dsn

Dimension mylogin (4) & define an array
Mylogin (1) = alltrim (thisform. text2.value) & server address, for example: 192.168.1.188
Mylogin (2) = alltrim (thisform. text4.value) & database name, for example: mydata
Mylogin (3) = alltrim (thisform. text3.value) & SQL query username example: SA
Mylogin (4) = alltrim (thisform. text1.value) & SA Password
Public nygxx & define global variables, connection handle
Nygxx = sqlstringconnect ('driver = SQL Server; server = & mylogin (1 ).; uid = & mylogin (3 ).; pwd = & mylogin (4 ).; database = & mylogin (2 ). ') & get the variable value through &
If! Empty (alltrim (mylogin (1) and! Empty (alltrim (mylogin (2 )))
If nygxx> 0
# Define odbc_add_dsn 1 & create if no DSN exists
# Define odbc_config_dsn 2 & reconfigure if DSN exists

# Define odbc_remove_dsn 3 & Delete the DSN if an error occurs
Declare integer sqlconfigdatasource in odbccp32; & call an API Function
Integer hwndparent ,;
Integer frequest ,;
String lpszdriver ,;
String lpszattributes
Pcdriver = 'SQL Server'
Pcserver = mylogin (1)
Pcdatabase = mylogin (2)
Pcuid = mylogin (3)
Pcpwd = mylogin (4)
Pcaccid = NULL
Pcuserid = NULL
Lpszdriver = pcdriver
Hwndparent = NULL
Lpszattributes = "Server =" + alltrim (pcserver) + CHR (0) +;
"Description = powerdsn" + CHR (0) +;
"DSN = mydsn" + CHR (0) + "database =" + alltrim (pcdatabase)
Nreturn = sqlconfigdatasource (0, odbc_config_dsn, lpszdriver, lpszattributes)
If nreturn = 0
Mreturn = sqlconfigdatasource (0, odbc_add_dsn, lpszdriver, lpszattributes)
If mreturn = 0
Clear DLLs
Endif
Else
Clear DLLs
Endif
Else
MessageBox ('network connection failed. Check whether the network, server address, or database is correct ', 48, 'infos ')
Endif
Else
If MessageBox ("the option cannot be blank for the server or database", 48 + 4, "Operation prompt") = 6
Return
Else
Quit
Clear events
Endif
Endif

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.