NSIS SQL Connection

When installing using my NSIS script installer, I need to run multiple script on SQL Server: select, update, build and paste.

How can I do this without having a SQL Server engine on the computer running the NSIS installer?

I thought about packing SQL Server Compact Edition into my installer so I can use it to connect to SQL Server. So should I go?

+3


source to share


2 answers


I found a plugin for NSIS that can connect to MS SQL database: MSSQL_OLEDB_plug-in

It can be used like this:



${OLEDB}::SQL_Logon    "$SQLSERVER" "$SQLUSER" "$SQLPASSWORD"
${OLEDB}::SQL_Execute  "$SQLQUERY"
${OLEDB}::SQL_GetError
${OLEDB}::SQL_GetRow
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
${OLEDB}::SQL_Logout

      

+2


source


You don't need a SQL Server engine to run queries on a remote machine, you need a driver.

One approach is to use a command line client, which also requires a built-in driver. You probably want to link or find the driver that your application uses in your installer.

In SQL Server 2005 or later, the command line client is called sqlcmd . It can be downloaded from the Feature Pack download pages ( 2005 2008 2008R2 2012 ).

So, this is just a question with a bundled SQL script with an installer and executing the script by calling sqlcmd with ExecWait .

You can run your script over a reliable connection with:



sqlcmd -S _SERVER\_INSTANCE_ -d _DBNAME_ -i _SCRIPT_FILE_

      

Or using SQL Login:

sqlcmd -S _SERVER\_INSTANCE_ -d _DBNAME_ -U _USERNAME_ -P _PASSWORD_ -i _SCRIPT_FILE_

      

A SQL 2000 version of this approach can be found here on the nsis wiki .

+6


source







All Articles