Old 20th March 2007, 04:54   #1
duMonaro
Junior Member
 
Join Date: Mar 2007
Posts: 2
Restore SQL database help

sorry guys i'm a noob. How do you restore a database with NSIS and where do i place the code?
duMonaro is offline  
Old 21st March 2007, 08:22   #2
sgiusto
Member
 
Join Date: Mar 2007
Location: Italy
Posts: 99
you should use you SQL command line utility to execute a sqlscript
to run your SQL command line utility you can use the ExecWait statement
If you are using MSSQL on windows machines you can use the MSSQL plugin
sgiusto is offline  
Old 21st March 2007, 23:48   #3
duMonaro
Junior Member
 
Join Date: Mar 2007
Posts: 2
I saw this code on one of the forum questions but it doesnt seem like something i'd use in NSIS code.

___________________________
::SET VARIABLES
set DBNAME=NAMEOFDATABASEBEINGRESTORED
set DBDIRECTORY=C:\Program Files\Microsoft SQL Server\MSSQL\Data

TITLE Restoring %DBNAME% Database

::PUT DATABASE IN SINGLE USER MODE TO ALLOW RESTORE
osql -E -d master -Q "alter database %DBNAME% set single_user with rollback immediate"

::RESTORE DATABASE
osql -E -d master -Q "restore database %DBNAME% from disk='%~dp0\%DBNAME%.bak' WITH MOVE '%DBNAME%_Data' TO '%DBDIRECTORY%\%DBNAME%_Data.MDF', MOVE '%DBNAME%_Log' TO '%DBDIRECTORY%\%DBNAME%_Log.LDF'"

::GRANT PERMISSION TO ASPNET USER
osql -E -d %DBNAME% -Q "sp_grantdbaccess '%COMPUTERNAME%\ASPNET'"
osql -E -d %DBNAME% -Q "sp_addrolemember 'db_owner', '%COMPUTERNAME%\ASPNET'"

::RESTORE TO MULTI USER
osql -E -d master -Q "alter database %DBNAME% set multi_user"

exit
duMonaro is offline  
Old 22nd March 2007, 08:09   #4
sgiusto
Member
 
Join Date: Mar 2007
Location: Italy
Posts: 99
Your example comes from a batch file I think.
NSIS code would be something like:
MSSQL_OLEDB::SQL_Logon /NOUNLOAD "$SQLSERVER" "$SQLUSER" "$SQLPASSWORD"
MSSQL_OLEDB::SQL_Execute /NOUNLOAD "alter database $DBNAME set single_user with rollback immediate"
MSSQL_OLEDB::SQL_Execute /NOUNLOAD "restore database $DBNAME from disk='${PATH}\${DBNAME}.bak' WITH MOVE '${DBNAME}_Data' TO '${DATADIR}\${DBNAME}_Data.MDF', MOVE '${DBNAME}_Log' TO '${DATADIR}\${DBNAME}_Log.LDF'"
MSSQL_OLEDB::SQL_Execute /NOUNLOAD "alter database ${DBNAME} set multi_user"

You need MSSQL Plugin and replace variables as appropriate
sgiusto is offline  
Closed Thread
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump