简体   繁体   中英

Create SQL connection using Install Script in InstallShield project

In InstallShiled setup project we have certain requirement that we need to validate any specific DataBase is exist or not on given SQL Server.

For that we are using below Install Script:

szADOConnObjID = "ADODB.Connection";
set pADOConnObj = CreateObject(szADOConnObjID); 

szConnString = "driver={SQL Server};"; // For TLS 1.2 Only use driver={SQL Server Native Client 11.0};
szConnString = szConnString + "server=HPSDEV67;";
szConnString = szConnString + "Initial Catalog=master;";
szConnString = szConnString + "Integrated Security=True";
MessageBox("SQL Connection String: " + szConnString, INFORMATION);

try
    MessageBox("Trying with Windows Authentication first", INFORMATION);
    if (pADOConnObj.State==0)then 
        pADOConnObj.Open(szConnString);
        MessageBox("Connection Success", INFORMATION);
    endif;  
catch
    MessageBox("Windows Authentication Catch",INFORMATION);
    MessageBox(Err.Description , SEVERE);
endcatch;

With above Install Script it gives below error:

---------------------------
Sample SQL Connect - InstallShield Wizard
---------------------------
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
---------------------------
OK   
---------------------------

Any idea what am I doing something wrong here?

After digging in detail I found fix for this from here .

For Non-TLS 1.2

szConnString = "Provider=SQLOLEDB;"
szConnString = szConnString + "data source=SQLServerName;"
szConnString = szConnString + "Initial Catalog=master;"
szConnString = szConnString + "Integrated Security=SSPI"

For TLS 1.2

szConnString = "Provider=SQLNCLI11;"
szConnString = szConnString + "SERVER=SQLServerName;"
szConnString = szConnString + "database=master;"
szConnString = szConnString + "Trusted_Connection=Yes"
msgbox "SQL Connection String: " + szConnString, INFORMATION

For TLS 1.2 is best solution because it's working in both environment.

Microsoft released new driver MSOLEDBSQL early this year 2018 and will continue to provide updates on this driver only.

https://blogs.msdn.microsoft.com/sqlnativeclient/2018/03/30/released-microsoft-ole-db-driver-for-sql-server/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM