Ich versuche, eine Verbindung mit SQL Server herzustellen und eine Skriptdatei während der Installation des Setup auszuführen. Ich habe es geschafft, ein einfaches Skript ohne GO
Anweisung auszuführen.Inno-Setup Ausführen einer großen SQL-Skriptdatei während der Installation
Frage: Gibt es eine Möglichkeit, das GO
Wort zu übergeben (überspringen) und das Skript ausführen?
ADOConnection.ConnectionString :=
'Provider=SQLOLEDB;' +
'Data Source=' + ServerEdit.Text + ';' +
'User Id=' + UsernameEdit.Text + ';' +
'Password=' + PasswordEdit.Text + ';' +
'Trusted_Connection=no;';
end;
ADOConnection.Open;
try
ADOCommand := CreateOleObject('ADODB.Command');
ADOCommand.ActiveConnection := ADOConnection;
ScriptPath := ExpandConstant('{tmp}\Script2.sql');
if LoadStringFromFile(ScriptPath, ssquery) then
begin
StringChangeEx(ssquery, 'GO', '', True);
SQLQuery := ssquery
ADOCommand.CommandText := SQLQuery;
ADOCommand.Execute(NULL, NULL, adCmdText or adExecuteNoRecords);
Result := True;
end;
finally
ADOConnection.Close;
end;
Die Script2.sql
USE northwind3
GO
/****** Object: StoredProcedure [dbo].[Customers By City] Script Date: 5/25/2016 8:35:45 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Customers By City]
-- Add the parameters for the stored procedure here
(@param1 NVARCHAR(20))
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT CustomerID, ContactName, CompanyName, City from Customers as c where [email protected]
END
GO
/****** Object: StoredProcedure [dbo].[Customers Count By Region] Script Date: 5/25/2016 8:35:45 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Customers Count By Region]
-- Add the parameters for the stored procedure here
(@param1 NVARCHAR(15))
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @count int
SELECT @count = COUNT(*)FROM Customers WHERE Customers.Region = @Param1
RETURN @count
END
HINWEIS: Ich verwende ADOB für die Verbindung in ähnlicher Weise TLama's Antwort auf How to connect to MS SQL Server using InnoSetup? Außer in meinem Fall habe ich GO
in meinem Skript enthalten.
Vielen Dank.
Nicht sicher, was das Problem ist. Fügen Sie einfach 'go' in die' .sql' Datei ein. –
@Martin Prikryl Das Problem ist 'GO' ist ein Batch-Terminator und die Verwendung in ADOCommand.Execute() ist falsch. Wirft eine Ausnahme wie "Falsche Syntax in der Nähe von 'GO'.". – abdul
Ist das nicht das gleiche wie das Ausführen mehrerer separater SQL-Skripte nacheinander? –