设为首页 收藏本站
查看: 522|回复: 0

[经验分享] 怎么使用sql弹出框

[复制链接]

尚未签到

发表于 2016-11-11 05:14:28 | 显示全部楼层 |阅读模式
转载 http://wglnngt-001.blog.163.com/blog/static/4077058420091114114652911/
How to use SQL Dialogs without Scripts  


Because so many people have problems with InstallShieldX using SQL Dialogs, I thought I might make this brief tutorial so users can get up and running without reading several hundred posts online. This tutorial can be used for InstallScript MSI Projects, but it may also help for InstallScript only Projects as well. 
First, I'd like to note that you should download the attached ZIP file which contains updated SQLRT.dll and ISSQLSRV.dll files. No, I did not create these, they were given to me from InstallShield as a fix that is not included in SP1 for InstallShieldX. They update a couple of Issues with InstallShieldX and ADO (such as timeouts, etc.). Also included is the updated SQLCONV.h file. The included zip file contains a Batch file which I created to help in putting these files in the correct location. You can run this batch file which will first backup your existing DLLs before overwriting them. 

  • Add the (.obl) Libraries On the Build menu, click on Settings. On the Compile/Link tab, add the following (.obl) Libraries (seperated by commas) if they do not exist: 
  • <ISProductFolder>\Script\SQLRuntime\Lib\SQLRT.obl 
  • <ISProductFolder>\Script\SQLRuntime\Lib\SQLCONV.obl


  • Add the required DLLs to the Binary Table Now, go to the Direct Editor and find the Binary table. Here we need to add the SQL DLLs that normally get included automatically when adding Scripts to an InstallShield Project. Add a new Item in the Binary table (where it says "Click here to add a new Item"). Add the Following information: 
  • For the 1st Item, enter the Name as ISSQLSRV.DLL. Now, when you click in the Data column, a dialog will popup asking what to do with the data. You want the Read binary from filename option. Click Browse and browse to <ProgramFiles>\InstallShieldX\Redist\Language Independent\i386\ISSQLSrv.dll. Next Click Open then Ok and the DLL will be added to the Binary table. 
  • For the 2nd Item, enter the Name as SQLRT.DLL. For the Data, browse to <ProgramFiles>\InstallShieldX\Redist\Compressed Files\Language Independent\Intel 32\SQLRT.dll.
  • Modify the "SQLConv.h" Header File NOTE: All script / header files talked about are located in <ProgramFiles>\InstallShieldX\Script.

This was something I ended up finding on my own. There seems to be a bug in the ifx.h header file. In order to actually use the SQL Runtime from InstallShield without scripts, you need to invoke a call to SQLRTInitialize(). This function is located in the SQLRT.h header file. No big deal you say, just include that file in the Setup.rul! It's not that easy. You see, there are two ifx.h files: one is loacted in the .\Script\Ifx\Include and the other in .\Script\Iswi\Include\. Which one your Script is linked to depends on the (.obl) file paths in Step 1. 
In the case with InstallScript MSI Projects, the Ifx.h file is linked from the .\Script\Iswi\Include\ directory. If we open that Ifx.h file, we can see that InstallShield tried to "think" for us and they included the SQLCONV.h (this line: #include "..\..\SQLRuntime\Include\SQLConv.h") file automatically. Why is this bad you ask? Well, we need to include the SQLRT.h file, but if you look in both that file and the SQLCONV.h file, you will see that they both define this function: external prototype LIST SQLRTGetServers( byval BOOL );! So, if you were to include the SQLRT.h file in your scripts at this point, you would get the following error trying to compile: 'SQLRTGetServers' : identifier already defined
So how do we get around this? Well, we only need the SQLRTInitialize() function and since both the SQLRT.h and the SQLCONV.h both use the SQLRT.dll functions, we just need to modify the SQLCONV.h file to include that function! So, here it is, what you've been waiting for... 

  • Add this line to the SQLCONV.h file: external prototype void SQLRTInitialize( byval string );. It doesn't really matter where, but I put it just above the other SQL functions.
  • Modify the "OnSQLLogin()" Function Well, here it is, the last step. We need to modify the OnSQLLogin function. Why? Well, this function displays the SQLLogin Dialog. But it does more than that, it extracts the DLLs from the Binary table and loads them into memory. Now, I give InstallShield credit for initially writing this script, but lets face it, they're not the best at writing concise code ! Please keep in mind that you could write your own functions to extract the DLLs once and then call multiple SQL Dialogs, but I am just trying to keep this simple for now.

Code: 
//--------------------------------------------------------------------------- 
// OnSQLLogin 
//--------------------------------------------------------------------------- 
function number OnSQLLogin( nReturn ) 
string sDLL, sMessage; 
string sHidden[MAX_PATH]; 
string sServer[MAX_PATH], sUser[MAX_PATH], sPassword[MAX_PATH], sAuth[10], sDB[MAX_PATH], sTemp[MAX_PATH]; 
number nResult, nSize, nRetVal; 
BOOL   bWinAuth, bDoneLogin; 
begin 
// Extract SQL Runtime dlls 
sDLL = SUPPORTDIR ^ "ISSQLSRV.DLL"; 
nResult = StreamFileFromBinary(  ISMSI_HANDLE, "ISSQLSRV.DLL", sDLL ); 
if (nResult = -1) then 
MessageBox("The \"ISSQLSRV.dll\" could not be extracted from the Binary Table.", SEVERE); 
abort; 
endif; 
UseDLL( sDLL ); 
sDLL = SUPPORTDIR ^ "SQLRT.DLL"; 
nResult = StreamFileFromBinary(ISMSI_HANDLE, "SQLRT.DLL", sDLL); 
if (nResult = -1) then 
    MessageBox("The \"SQLRT.DLL\" could not be extracted from the Binary Table.", SEVERE); 
    abort; 
endif; 
UseDLL( sDLL ); 
     
SQLRTInitialize(""); 
// Add the Password property as a Hidden property so no passwords accidentally get logged. 
nSize = MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "MsiHiddenProperties", sHidden, nSize ); 
if (StrLength(sHidden) > 0) then sHidden = sHidden + ";"; endif; 
sHidden = sHidden + "IS_SQLSERVER_PASSWORD"; 
MsiSetProperty( ISMSI_HANDLE, "MsiHiddenProperties", sHidden ); 

// Get Default properties 
nSize = MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_SERVER", sServer, nSize ); 
nSize = MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_DATABASE", sDB, nSize ); 
nSize = MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_USERNAME", sUser, nSize ); 
nSize = MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_PASSWORD", sPassword, nSize ); 
nSize = 10; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_AUTHENTICATION", sAuth, nSize ); 
if (sAuth = "1") then 
bWinAuth = FALSE; 
else 
bWinAuth = TRUE; 
endif; 

bDoneLogin = FALSE; 
while( !bDoneLogin ) 
// Show login dialog 
nReturn = SQLServerSelectLogin( sServer, sUser, sPassword, bWinAuth ); 
if (nReturn = BACK) then 
// BACK was clicked, so we don't even try 
bDoneLogin = TRUE; 

elseif (nReturn = NEXT) then 
// Validate Connection 
MsiSetProperty( ISMSI_HANDLE, "IS_SQLSERVER_SERVER", sServer ); 
MsiSetProperty( ISMSI_HANDLE, "IS_SQLSERVER_USERNAME", sUser ); 
MsiSetProperty( ISMSI_HANDLE, "IS_SQLSERVER_PASSWORD", sPassword ); 
if (bWinAuth = TRUE) then 
sAuth = "0"; 
else 
sAuth = "1"; 
endif; 
MsiSetProperty( ISMSI_HANDLE, "IS_SQLSERVER_AUTHENTICATION", sAuth ); 
MsiSetProperty( ISMSI_HANDLE, "IS_SQLSERVER_CA_SILENT", "0" ); 
nRetVal = SQLRTServerValidate( ISMSI_HANDLE ); 
           
nSize = MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_STATUS", sTemp, nSize ); 
if( sTemp != "0" ) then 
nSize = _MAX_PATH; MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_STATUS_ERROR", sMessage, nSize ); 
if (nSize = 0) then sMessage = SdLoadString( IDS_IFX_SQL_ERROR_LOGIN_FAILED ); endif; 
MessageBox( sMessage, MB_OK ); 
else 
// Validation Successful 
bDoneLogin = TRUE; 
endif; 
else 
        MessageBox("General Errors Occured showing the SQL Server Login Dialog.", SEVERE); 
        abort; 
endif; 
endwhile; 
return nReturn; 
end; 


Well, I think that's it. I tried to get everything in here as concise and informative as possible. If anyone has problems with this, let me know!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-298518-1-1.html 上篇帖子: sql常用的 高级编程 下篇帖子: Orchard
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表