/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ * /
/ * * /
/ * Function: buildsqlserverdsn * /
/ * * /
/ * Descrip: Use Custom SqlServer's DSN DLG to CREATE DSN. * /
/ * * /
/ * Misc: * /
/ * * /
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ * /
Function Buildsql ServerDSN (Bfirststep, Ballownotset, Sztitle)
Bool bdone;
Number nMessage;
String szsqladdr, szsqldb, szdbusername, szdbuserpwd, szsqldsn
Short ndsntype;
String svarg [1024];
String SVDSN, SVADDR, SVDB, SVUID, SVPWD;
Number nsplitpos;
HWND HWNDDLG;
Bool bbuildresult;
Short Werrmsglen;
String szerrmsg [max_path 1];
Long dwerrcode;
Begin
BDONE = false;
// Define a dialog with EZDefinedialog
NMESSAGE = EZDEfinedialog (DSN_SQLSERVER_DLG, ISUSER, "", DLG_DSN_SQLSERVER);
IF (NMessage = DLG_ERR) THEN
MessageBox ("Cannot Configure SQLServer Data Sources - Can't find dialog box", severe);
BDONE = TRUE;
Endif;
While (bdone = false)
NMESSAGE = Waitondialog (DSN_SQLSERVER_DLG);
Switch (NMessage)
Case DLG_INIT:
HWnddlg = cmdgethwnddlg (DSN_SQLSERVER_DLG);
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
IF (bfirststep) THEN
_WinsubenableControl (hwnddlg, sd_pbut_back, 0);
Endif;
_Winsubsetwindowtitle (hwnddlg, sztitle);
CtrlStState (DSN_SQLSERVER_DLG, IDC_RADIO_DSN_USER, Button_Checked);
Case DLG_ERR:
MessageBox ("Cannot Display Configure SQLServer Data Source Dialog", Severe);
BDONE = TRUE;
Case Cancel:
BDONE = TRUE;
Case DLG_Close:
BDONE = TRUE;
Case SD_PBUT_CONTINUE:
// Call the interface Add a DSN
// ...
CtrlgetText (DSN_SQLSERVER_DLG, IDC_EDIT_DB_ADDR, SZSQLADDR);
CtrlgetText (DSN_SQLSERVER_DLG, IDC_EDIT_SQLSERVER_DB, SZSQLDB);
CtrlgetText (DSN_SQLSERVER_DLG, IDC_EDIT_SQLSERVER_USER_NAME, SZDBUSERNAME);
CtrlgetText (DSN_SQLSERVER_DLG, IDC_EDIT_SQLSERVER_USER_PWD, SZDBUSERPWD);
CtrlgetText (DSN_SQLSERVER_DLG, IDC_EDIT_SQLSERVER_DSN, SZSQLDSN);
IF (Strlength (Szsqladdr) = 0) THEN
IF (askyesno ("No input server, is it configured later?", yes) = no) THEN
_WinsubfocusControl (hwnddlg, idc_edit_db_addr);
Else
BDONE = TRUE;
Endif;
Elseif (Strlength (szsqldb) = 0) THEN
IF (askyesno ("No input database, is it configured in the future?", yes) = no) THEN
_WinsubfocusControl (hwnddlg, idc_edit_sqlserver_db);
Else
BDONE = TRUE;
Endif;
Elseif (Strlength) = 0) THEN
IF (askyesno ("No input database user, is it configured in the future?", yes) = no) THEN
_WinsubfocusControl (hwnddlg, idc_edit_sqlserver_user_name);
Else
BDONE = TRUE;
Endif;
Elseif (Strlength (Szsqldsn) = 0) THEN
If (askYesno ("does not enter the data source name, is it configured in the future?", yes) = no) THEN
_WinsubfocusControl (hwnddlg, idc_edit_sqlserver_dsn);
Else
BDONE = TRUE;
Endif;
Else
// All data has been obtained, you can call SQLConfigDataSource to add data source.
// Organize statement
// Note: Because the DSN does not save the UID and PWD, these two cannot be added in Attribute.
// Keyword, and each critical part divided by '/ 0', due to InstallShield
/ / Do not support a string in the middle of a string '/ 0', so it is not possible to use connection directly
// Keyword, below is a variant method
IF (CtrlgetState (DSN_SQLSERVER_DLG, IDC_RADIO_DSN_USER) = Button_Checked) THEN
NDSNTYPE = ODBC_ADD_DSN; ELSE
ndsntype = odbc_add_sys_dsn;
Endif;
SVDSN = "DSN =" szsqldsn;
svaddr = "server =" szsqladdr;
SVDB = "database =" szsqldb;
Svuid = "uid =" szdbusername;
Svpwd = "pwd =" szdbuserpwd;
Svarg = SVDSN '' SVADDR '' SVDB;
nsplitpos = Strlength; SVDSN
Svarg [nsplitpos] = '/ 0';
NSPLITPOS = Strlength (SVADDR) 1;
Svarg [nsplitpos] = '/ 0';
NSplitpos = Strlength (SVDB) 1;
Svarg [nsplitpos] = '/ 0';
// Call SQLConfigDataSource in ODBCCP32 Add a DSN
// If false returns, indicates that the addition failed, then you can call it.
// SQLINSTALLERROR to get a reason for failure
BBUILDRESULT = SQLConfigDataSource (Null, NDSNTYPE, "SQL Server", Svarg);
IF (bBUILDRESULT) THEN
// If you add success
BDONE = TRUE;
Else
// add failed
WERRMSGLEN = max_path;
Sqlinstallererror (1, & DwerRcode, Szerrmsg, Werrmsglen, & Werrmsglen);
IF (ballownotset) THEN
Szerrmsg = "Configure the data source failed -" Szerrmsg "! Is it configured later?"
IF (askyesno (szerrmsg, yes) = no) THEN
BDONE = false;
Else
BDONE = TRUE;
Endif;
Else
Szerrmsg = "Configure the data source failed -" Szerrmsg "!"
MessageBox (Szerrmsg, Severe);
Endif;
Endif;
Endif;
Case SD_PBUT_BACK:
// Previous
BDONE = TRUE;
Case SD_PBUT_EXITSETUP:
BDONE = TRUE;
Case IDC_Radio_DSN_User:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
Case IDC_Radio_dsn_system:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
Case IDC_EDit_db_addr:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
Case IDC_EDit_sqlser_user_name:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET); CASE IDC_EDIT_SQLSERVER_USER_PWD:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
Case IDC_EDIT_SQLSERVER_DSN:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
Case IDC_EDit_sqlser_db:
Checksql ServerDsnInputValid (HWNDDLG, BALLOWNOTSET);
Endswitch;
Endwhile;
Enddialog (DSN_SQLSERVER_DLG);
ReleaseDialog (DSN_SQLSERVER_DLG);
IF (NMessage = SD_PBUT_CONTINUE) THEN
Return NEXT;
Elseif (NMessage = SD_PBUT_BACK) THEN
Return back;
Else
Do (exit);
Endif;
END;