|
|
#1 |
|
Junior Member
|
NSIS execute *.bat or *.exe
Hallo,
i try to explain my problem. I want to execute a .bat file from to installer, that attach a database to a SQLEXPRESS 2005. The Same with the .exe file. Here is the .bat content: sqlcmd -U user -P pw -S %computername%\test -Q "sp_attach_db 'test','%Programfiles%\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test.mdf','%Programfiles%\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test_log.ldf'" Now my problem when I execute the .bat or exe file self it works. When I execute it from the installer not. Help me please. |
|
|
|
|
|
#2 |
|
Major Dude
Join Date: Feb 2007
Posts: 672
|
How do you call the bat file?
You can use the MSSQL OLEDB plug-in to attach the database as well (usefull if you have to do more than just attaching). http://nsis.sourceforge.net/MSSQL_OLEDB_plug-in |
|
|
|
|
|
#3 |
|
Junior Member
|
Okay i tried it with MSSQL OLEDB.
Login into SQLEXPRESS Works but then came "Quary Failed".Why? Here the script: NSIS SetOutPath "$Temp" File "D:\db_connect.sql" ReadRegStr $R3 HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName" MSSQL_OLEDB::SQL_Logon "$R3\SQLEXPRESS" "SA" "TEST" MSSQL_OLEDB::SQL_Execute "$Temp\db_connect.sql" MSSQL_OLEDB::SQL_Logout db_connect.sql sp_attach_db 'test','%Programfiles%\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test.mdf','%Programfiles%\Microsoft SQL Server\MSSQL.1\MSSQL\Data\test_log.ldf' Thank you for your help Okay I found my problem i used MSSQL_OLEDB::SQL_Execute and not MSSQL_OLEDB::SQL_ExecuteScript. But now came "Error initializing script". Why? Last edited by H-Block; 18th May 2009 at 06:08. |
|
|
|
|
|
#4 |
|
Major Dude
Join Date: Feb 2007
Posts: 672
|
Try following as your sql script
code: |
|
|
|
|
|
#5 |
|
Junior Member
|
Thank you for your fast answer.
I tried your code but it doesn't work. There is the same error. Error initializing script. When I testing it with the Example from MSSQL_OLEDB the Error is: Extract: test.sql Loggin on to SQL server Notebook\test 0 Logon successfull 0 SQL State: 0x00000000 - Native: 0 - Message: 1 Query Failed 0 SQL State: 0x80040e14 - Native: 0 - Message: Wrong Syntax in the near of '\'. 1 Error getting rowset 1 Error getting rowset 0 SQL State: 0x00000000 - Native: 0 - Message: 0 Script executed successfully 0 SQL State: 0x00000000 - Native: 0 - Message: 0 Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86) Oct 14 2005 00:33:37 Copyright (c) 1988-2005 Microsoft Corporation Express Edition on Windows NT 5.1 (Build 2600: Service Pack 3) 2 No more data 0 SQL State: 0x00000000 - Native: 0 - Message: Completed When I connect to the SQL server over cmd--> sqlcmd and paste your code it works. |
|
|
|
|
|
#6 |
|
Junior Member
|
Okay I found my problem and fixed it.
Now I have another Problem. I want to create a user with this script: MSSQL_OLEDB::SQL_Execute "CREATE LOGIN test WITH PASSWORD = '123456';USE testdb;CREATE USER test FOR LOGIN test WITH DEFAULT_SCHEMA = dbo;Exec sp_addrolemember'db_owner','test'" Login into server is okay. Have I anything vorgotten? |
|
|
|
|
|
#7 | ||
|
Major Dude
Join Date: Feb 2007
Posts: 672
|
Quote:
Quote:
Use this instead: code: |
||
|
|
|
|
|
#8 |
|
Junior Member
|
Okay Thank you it Works.
Here is the code I used. For SQLEXPRESS install: Function ExistsMSDE ExecWait "$Temp\SQL.EXE -q /norebootchk /qb reboot=ReallySuppress addlocal=all instancename=SQLEXPRESS SCCCHECKLEVEL=IncompatibleComponents:1;MDAC25Version:0 ERRORREPORTING=1 SQLAUTOSTART=1 SAPWD=test SECURITYMODE=SQL DISABLENETWORKPROTOCOLS=0" Sleep 10000 ; wait for a 10 seconds FunctionEnd For Database: ReadRegStr $R3 HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName" MSSQL_OLEDB::SQL_Logon "$R3\SQLEXPRESS" "sa" "test" MSSQL_OLEDB::SQL_Execute "CREATE DATABASE [DB_name] ON ( FILENAME = N'$Programfiles\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DB.mdf' ),( FILENAME = N'$Programfiles\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DB_log.ldf' ) FOR ATTACH GO" MSSQL_OLEDB::SQL_Logout For User: ReadRegStr $R3 HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName" MSSQL_OLEDB::SQL_Logon "$R3\SQLEXPRESS" "sa" "test" MSSQL_OLEDB::SQL_Execute /NOUNLOAD "CREATE LOGIN user WITH PASSWORD = 'PW'" MSSQL_OLEDB::SQL_Execute /NOUNLOAD "USE DB_name" MSSQL_OLEDB::SQL_Execute /NOUNLOAD "CREATE USER user FOR LOGIN user WITH DEFAULT_SCHEMA= dbo_owner" MSSQL_OLEDB::SQL_Execute /NOUNLOAD "Exec sp_addrolemember 'db_owner', 'user'" MSSQL_OLEDB::SQL_Logout Thank you for your fast Help. |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|